Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_find_element_splinter(self, page, splinter, splinter_strategy):
locator = (splinter_strategy, str(random.random()))
from splinter.element_list import ElementList
page.driver.configure_mock(
**{"find_by_{0}.return_value".format(splinter_strategy): ElementList([])}
)
Region(page).find_element(*locator)
getattr(
page.driver, "find_by_{0}".format(splinter_strategy)
).assert_called_once_with(locator[1])
def test_element_should_be_a_elementList(self):
"should be element list"
element = self.browser.within('body')
assert isinstance(element, ElementList)
def test_is_element_present_not_present_splinter(self, region, splinter_strategy):
from splinter.element_list import ElementList
locator = (splinter_strategy, str(random.random()))
with patch(
"pypom.splinter_driver.Splinter.find_elements", new_callable=MagicMock()
) as mock_find_elements:
mock_find_elements.return_value = ElementList([])
assert not region.is_element_present(*locator)
def test_fill_action_with_missing_element_raises(
self,
mocked_browser
):
driver = self._get_driver(mocked_browser)
element = ElementList([])
with self.assertRaises(ActionNotPerformableException):
driver.fill(element, 'some-text')
def test_find_elements_splinter(self, page, splinter, splinter_strategy):
locator = (splinter_strategy, str(random.random()))
from splinter.element_list import ElementList
page.driver.configure_mock(
**{"find_by_{0}.return_value".format(splinter_strategy): ElementList([])}
)
Region(page).find_elements(*locator)
getattr(
page.driver, "find_by_{0}".format(splinter_strategy)
).assert_called_once_with(locator[1])
def test_attribute_error_method_for_empty(self):
"""
should raise ElementDoesNotExist when the list is empty
and someone tries to access a method or property on the child element.
"""
with self.assertRaises(ElementDoesNotExist):
the_list = ElementList([])
the_list.unknown_method()
def find_by_name(self, name):
html = self.htmltree
xpath = '//*[@name="%s"]' % name
elements = []
for xpath_element in html.xpath(xpath):
elements.append(xpath_element)
find_by = "name"
query = xpath
return ElementList(
[LxmlControlElement(element, self) for element in elements],
find_by=find_by,
query=query,
)
def find_by(self, finder, selector):
elements = None
end_time = time.time() + self.wait_time
while time.time() < end_time:
try:
elements = finder(selector)
except WebDriverException:
elements = []
if not isinstance(elements, list):
elements = [elements]
if elements:
return ElementList(elements)
return ElementList([])
def find_by_css(self, selector):
elements = self._element.cssselect(selector)
return ElementList([self.__class__(element, self) for element in elements])