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_by_value_in_element_context(self):
elements = self.browser.find_by_css("#inside")
decendent = elements[0].find_by_value("crazy diamond")
self.assertEqual(len(decendent), 1)
self.assertIsInstance(decendent, ElementList)
self.assertIsInstance(decendent.first, ElementAPI)
def _element_is_link(self, element):
return element.tag == "a"
def _element_is_control(self, element):
return hasattr(element, "type")
@property
def cookies(self):
return self._cookie_manager
re_extract_inner_html = re.compile(r"^<[^<>]+>(.*)]+>$")
class ZopeTestBrowserElement(ElementAPI):
def __init__(self, element, parent):
self._element = element
self.parent = parent
def __getitem__(self, attr):
return self._element.attrib[attr]
def find_by_css(self, selector):
elements = self._element.cssselect(selector)
return ElementList([self.__class__(element, self) for element in elements])
def find_by_xpath(self, selector):
elements = self._element.xpath(selector)
return ElementList([self.__class__(element, self) for element in elements])
def find_by_name(self, name):
def test_find_by_css_in_element_context(self):
"should find elements by css in element context and should return splinter driver element"
elements = self.browser.find_by_css("#inside")
decendent = elements[0].find_by_css("h2")
self.assertEqual(decendent.text.strip(), "inside")
self.assertIsInstance(decendent, ElementList)
self.assertIsInstance(decendent[0], ElementAPI)
field = self.find_by_name(name)
field.click()
def check(self, name):
field = self.find_by_name(name)
field.check()
def uncheck(self, name):
field = self.find_by_name(name)
field.uncheck()
def quit(self):
self.driver.quit()
class WebDriverElement(ElementAPI):
def __init__(self, element):
self._element = element
def _get_value(self):
if self._element.get_value():
return self._element.get_value()
else:
return self._element.get_text()
def _set_value(self, value):
self._element.clear()
self._element.send_keys(value)
value = property(_get_value, _set_value)
for cookie in self.driver.get_cookies():
cookies[cookie['name']] = cookie['value']
return cookies
def add_cookie(self, cookie):
self.driver.add_cookie({'name': cookie.keys()[0],
'value': cookie.values()[0]})
def delete_cookies(self):
self.driver.delete_all_cookies()
def delete_cookie(self, key):
self.driver.delete_cookie(key)
class WebDriverElement(ElementAPI):
def __init__(self, element, parent):
self._element = element
self.parent = parent
def _get_value(self):
value = self["value"]
if value:
return value
else:
return self._element.text
def _set_value(self, value):
self._element.clear()
self._element.send_keys(value)
def windows(self):
return Windows(self)
class TypeIterator(object):
def __init__(self, element, keys):
self._element = element
self._keys = keys
def __iter__(self):
for key in self._keys:
self._element.send_keys(key)
yield key
class WebDriverElement(ElementAPI):
find_by = find_by
def __init__(self, element, parent):
self._element = element
self.parent = parent
self.driver = self.parent.driver
self.wait_time = self.parent.wait_time
self.element_class = self.parent.element_class
self.links = FindLinks(self)
def _get_value(self):
return self["value"] or self._element.text
def _set_value(self, value):
if not self._is_text_present(text):
return True
return False
def _element_is_link(self, element):
return element.tag == "a"
def _element_is_control(self, element):
return element.tag in ["button", "input", "textarea"]
@property
def cookies(self):
return self._cookie_manager
class LxmlElement(ElementAPI):
def __init__(self, element, parent):
self._element = element
self.parent = parent
def __getitem__(self, attr):
return self._element.attrib[attr]
def find_by_css(self, selector):
elements = self._element.cssselect(selector)
return ElementList([self.__class__(element, self) for element in elements])
def find_by_xpath(self, selector):
elements = self._element.xpath(selector)
return ElementList([self.__class__(element, self) for element in elements])
def find_by_name(self, name):