10 examples of 'selenium find all elements' in Python

Every line of 'selenium find all elements' 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
72def all(self, css_or_xpath_or_by: Union[str, tuple]) -> Collection:
73 by = to_by(css_or_xpath_or_by)
74
75 return Collection(
76 Locator(f'{self}.all({by})',
77 lambda: self().find_elements(*by)),
78 self.config)
5def find_element(driver, locator):
6 return WebDriverWait(driver, 2).until(
7 EC.presence_of_element_located(locator))
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)
35def _elements(self, css_selector):
36 return self.root.find_elements_by_css_selector(css_selector)
227def waitForElements(self, css_selector, timeout=DEFAULT_WAIT_TIMEOUT,
228 visible=None):
229 """ Waits for DOM elements matching the provided CSS selector to be
230 available.
231
232 Args:
233 - css_selector: CSS selector string
234
235 Kwargs:
236 - timeout: Operation timeout in seconds
237 - visible: Ensure elements visibility status:
238 * True: wait for visible elements only
239 * False: wait for invisible elements only
240 * None: skip visibility status checks
241
242 Returns: List of DOM elements
243 """
244 def get_element_checker(driver, visible):
245 locator = (By.CSS_SELECTOR, css_selector)
246 if visible is True:
247 return EC.visibility_of_element_located(locator)
248 if visible is False:
249 return EC.invisibility_of_element_located(locator)
250 return lambda _: driver.find_elements_by_css_selector(css_selector)
251
252 message = u"Couldn't find elems matching %s (visibility check: %s)" % (
253 css_selector, visible)
254 WebDriverWait(self, timeout, poll_frequency=.25).until(
255 get_element_checker(self, visible), message=message)
256
257 return self.find_elements_by_css_selector(css_selector)
497def find_elements_by_name(self, name):
498 """
499 Finds elements by name.
500
501 :Args:
502 - name: The name of the elements to find.
503
504 :Returns:
505 - list of webelement - a list with elements if any was found. an
506 empty list if not
507
508 :Usage:
509 elements = driver.find_elements_by_name('foo')
510 """
511 return self.find_elements(by=By.NAME, value=name)
14def find_elements(self,driver,para_list,is_displayed=True,text=''):
15 """
16 Find elements using the given condition..
17
18 :param driver:
19 :param para_list: [method, value] eg : ['id','add_btn']
20 :param is_displayed: True : Only the elements shown on the page will be returned. False: Elements will also be returned no matter is shown or hidden.
21 :param text: Only the elements contain the specified text will be returned.
22 :return: Found element list.
23 """
24 method, value = para_list[0], para_list[1]
25 if 'css' in method:
26 method = By.CSS_SELECTOR
27 elif 'class' in method:
28 method = By.CLASS_NAME
29 elif 'text' in method:
30 method = By.PARTIAL_LINK_TEXT
31 elif 'tag' in method:
32 method = By.TAG_NAME
33 elements = driver.find_elements(by=method,value=value)
34 new_elements = []
35 for element in elements:
36 if text != '':
37 if self.is_text_in_element(element,text):
38 if is_displayed:
39 if element.is_displayed():
40 new_elements.append(element)
41 else:
42 new_elements.append(element)
43 else:
44 if is_displayed:
45 if element.is_displayed():
46 new_elements.append(element)
47 else:
48 new_elements.append(element)
49 return new_elements
38def test_element_find_multiple_elements(self):
39 el = self.driver.find_element_by_class_name('android.widget.ListView')
40
41 sub_els = el.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
42 self.assertIsInstance(sub_els, list)
120def find_element_by_link_text(self, *args, **kwargs):
121 return self.__getattr_from_webdriver_or_webelement__('find_element_by_link_text')(*args, **kwargs)
93def find_elements(self , text='' , tag='button', id ='' , classname ='', number = 1 , css_selector='' , xpath='' , loose_match = True):
94 '''Returns a list of elements that best fit the given parameters'''
95 return self.__find_element(text, tag , classname , id , number , css_selector , xpath , loose_match)

Related snippets