Skip to content

Commit

Permalink
Merge pull request #151 from ramgml/fix_element_getx
Browse files Browse the repository at this point in the history
bugfix: fixed findx and getx of the Element class. Element instead of…
  • Loading branch information
ElSnoMan authored Dec 21, 2020
2 parents 0e30017 + b02ac9d commit bd384e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pylenium/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ def getx(self, xpath: str, timeout: int = None) -> 'Element':
lambda _: self.webelement.find_element(by, xpath),
f'Could not find any elements with the xpath ``{xpath}``'
)
return Element(self, elements, locator=(by, xpath))
return Element(self.py, elements, locator=(by, xpath))

def findx(self, xpath: str, timeout: int = None) -> 'Elements':
""" Finds the DOM elements that matches the `xpath` selector.
Expand All @@ -1256,7 +1256,7 @@ def findx(self, xpath: str, timeout: int = None) -> 'Elements':
)
except TimeoutException:
elements = []
return Elements(self, elements, locator=(by, xpath))
return Elements(self.py, elements, locator=(by, xpath))

def children(self) -> Elements:
""" Gets the Child elements. """
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/test_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,20 @@ def test_element_invalid_css_property_name(py):
element = py.contains('Click Me')
assert element.css_value('bg-color') == ''
assert element.css_value('length') is None


def test_getx_nested_element(py):
py.visit('https://demoqa.com/automation-practice-form')
container = py.getx('//*[@id="subjectsContainer"]')
element = container.getx('.//input')
element_id = element.get_attribute('id')
assert element_id == 'subjectsInput'


def test_findx_nested_element(py):
py.visit('https://demoqa.com/automation-practice-form')
container = py.getx('//*[@id="hobbiesWrapper"]')
elements = container.findx('.//input')
assert len(elements) == 3
for element in elements:
assert element.get_attribute('type') == 'checkbox'

0 comments on commit bd384e9

Please sign in to comment.