Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _is_text_present(self, text):
try:
body = self.find_by_tag("body").first
return text in body.text
except ElementDoesNotExist:
# This exception will be thrown if the body tag isn't present
# This has occasionally been observed. Assume that the
# page isn't fully loaded yet
return False
def test_raise_exception_on_indexerror_with_unicode_query(self):
"should raise ElementDoesNotExist exception on IndexError"
with self.assertRaises(ElementDoesNotExist):
ElementList([], query=u".element[title=título]").first
def test_element_list_raises_with_unicode_query(self):
with self.assertRaises(ElementDoesNotExist):
self.browser.find_by_css(u".element[title=título]").last
def test_element_query_should_raises_when_element_first_doest_exists(self):
with self.assertRaises(ElementDoesNotExist):
self.browser.find_by_css(".element-that-dont-exists").first
def test_raise_exception_on_indexerror(self):
"should raise ElementDoesNotExist exception on IndexError"
with self.assertRaises(ElementDoesNotExist):
ElementList([]).first
def i_select(context, value, name):
try:
context.browser.select(name, value)
except ElementDoesNotExist:
inp = context.browser.find_by_xpath("//input[@name='%s'][@value='%s']" % (name, value))
assert inp, u'Element not found'
inp.first.check()
def __getitem__(self, index):
if not isinstance(index, int) and not isinstance(index, slice):
return self.first[index]
try:
return self._container[index]
except IndexError:
raise ElementDoesNotExist(
u'no elements could be found with {0} "{1}"'.format(
self.find_by, self.query
)
def _is_text_present(self, text):
try:
body = self.find_by_tag("body").first
return text in body.text
except ElementDoesNotExist:
# This exception will be thrown if the body tag isn't present
# This has occasionally been observed. Assume that the
# page isn't fully loaded yet
return False
def set_variable(context, key, chain):
assert isinstance(
context.browser,
IOSWebDriver), 'iOS class chain only available on iOS devices'
assert context.persona is not None, u'no persona is setup'
try:
context.persona[key] = context.browser.find_by_ios_class_chain(
chain).first.get_attribute('value')
except ElementDoesNotExist:
assert False, u'Element not found'
def set_key_to_xpath_attr(context, key, attr, xpath):
assert context.persona is not None, u'no persona is setup'
try:
el = context.browser.find_by_xpath(xpath)
except ElementDoesNotExist:
assert False, u'Element not found'
context.persona[key] = el.first[attr] or ''