Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def find_option_by_text(self, text):
html = self.htmltree
element = html.xpath('//option[normalize-space(text())="%s"]' % text)[0]
control = LxmlControlElement(element.getparent(), self)
return ElementList(
[LxmlOptionElement(element, control)], find_by="text", query=text
)
def find_option_by_value(self, value):
html = self.htmltree
element = html.xpath('//option[@value="%s"]' % value)[0]
control = LxmlControlElement(element.getparent(), self)
return ElementList(
[LxmlOptionElement(element, control)], find_by="value", query=value
)
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_xpath(self, xpath, original_find=None, original_selector=None):
html = self.htmltree
elements = []
for xpath_element in html.xpath(xpath):
if self._element_is_link(xpath_element):
return self._find_links_by_xpath(xpath)
elif self._element_is_control(xpath_element):
elements.append((LxmlControlElement, xpath_element))
else:
elements.append((LxmlElement, xpath_element))
find_by = original_find or "xpath"
query = original_selector or xpath
return ElementList(
[element_class(element, self) for element_class, element in elements],
find_by=find_by,
query=query,
)