Skip to content

Commit

Permalink
Add doc section for shadowroot support
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Apr 11, 2019
1 parent 0efecea commit f7195de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion docs/page_objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ locator tuple.
form = PageElement(By.XPATH, "//form[@id='login']")
login_button = Button(By.XPATH, "./button", parent=form)
Shadowroot
~~~~~~~~~~

Page elements have an optional argument *shadowroot*, with the CSS selector of the shadowroot parent. The page element
will be searched within the shadowroot parent element, instead of the entire page.

It is only supported for PageElement objects identified by CSS, so it is not supported for PageElements, Group,
elements with nested encapsulation or PageElement identified by other selector types.

.. code-block:: python
login_button = Button(By.CSS_SELECTOR, "css_selector", shadowroot="shadowroot_css_selector")
Group
~~~~~
Expand All @@ -115,7 +127,6 @@ instead of the entire page.
self.form.password.text = password
self.form.login_button.click()
Find multiple page elements
---------------------------

Expand Down
8 changes: 5 additions & 3 deletions toolium/pageelements/page_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ def _find_web_element(self):
# If the element is encapsulated we use the shadowroot tag in yaml (eg. Shadowroot: root_element_name)
if self.shadowroot:
if self.locator[0] != By.CSS_SELECTOR:
raise Exception('Locator type should be CSS_SELECTOR but found: '.format(self.locator[0]))
raise Exception('Locator type should be CSS_SELECTOR using shadowroot but found: '
'%s'.format(self.locator[0]))
# querySelector only support CSS SELECTOR locator
self._web_element = self.driver.execute_script('return document.querySelector("%s")'
'.shadowRoot.querySelector("%s")' % (self.shadowroot, self.locator[1]))
self._web_element = self.driver.execute_script('return document.querySelector("%s").shadowRoot.'
'querySelector("%s")' % (self.shadowroot,
self.locator[1]))
else:
# Element will be finded from parent element or from driver
base = self.utils.get_web_element(self.parent) if self.parent else self.driver
Expand Down

0 comments on commit f7195de

Please sign in to comment.