10 examples of 'find element by xpath selenium python' in Python

Every line of 'find element by xpath selenium python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
254def get_element_by_xpath(self, selector):
255 """
256 Gets an element using an xPath selector.
257 """
258 raise NotImplementedError(
259 "This browser doesn't support getting elements by xpath")
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

5def find_element(driver, locator):
6 return WebDriverWait(driver, 2).until(
7 EC.presence_of_element_located(locator))
395def xpath(self, target, eager=False, timeout=None):
396 return self.waitfor("xpath", target, eager, timeout)
54def find_by_text(self, tag, text):
55 return self.wait_until_visible((By.XPATH,"//" + tag + "[contains(.,'" + text + "')]"))
972def select_by_id(self, element_id, text='', index=-1, timeout_in_seconds=None):
973 """
974 Selects element with particular text on it.
975 :param element_id:
976 :param text:
977 """
978 print "Executing select_by_id id = {0}, text = {1}".format(element_id, text)
979 self.wait_for_text_present_by_id(element_id, text, timeout_in_seconds=timeout_in_seconds)
980 if index == -1:
981 print "Selecting element with text = {1} by id = {0}".format(element_id, text)
982 Select(self.driver.find_element_by_id(element_id)).select_by_visible_text(text)
983 else:
984 print "Selecting element with index = {1} by id = {0}".format(element_id, index)
985 Select(self.driver.find_element_by_id(element_id)).select_by_index(index)
120def find_element_by_link_text(self, *args, **kwargs):
121 return self.__getattr_from_webdriver_or_webelement__('find_element_by_link_text')(*args, **kwargs)
40def is_element_exist(driver, xpath):
41 s = driver.find_elements_by_xpath(xpath=xpath)
42 if len(s) == 0:
43 print("元素未找到:%s"%xpath)
44 return False
45 elif len(s) == 1:
46 return True
47 else:
48 print("找到%s个元素:%s"%(len(s),xpath))
49 return False
129def find_elements_by_partial_link_text(self, *args, **kwargs):
130 return self.__getattr_from_webdriver_or_webelement__('find_elements_by_partial_link_text')(*args, **kwargs)
80def wait_on_element(driver, xpath, timeout=120):
81 num = 0
82 while is_element_present(driver, xpath) is False:
83 if num >= timeout:
84 return False
85 else:
86 num += 1
87 time.sleep(1)
88 return True
15def text(self, selector):
16 return selector.text

Related snippets