MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / find_elements

Method find_elements

py/selenium/webdriver/remote/webdriver.py:1013–1036  ·  view source on GitHub ↗

Find elements given a By strategy and locator. Args: by: The locating strategy to use. Default is `By.ID`. Supported values include: By.ID, By.NAME, By.XPATH, By.CSS_SELECTOR, By.CLASS_NAME, By.TAG_NAME, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,

(self, by: str | By | RelativeBy = By.ID, value: str | None = None)

Source from the content-addressed store, hash-verified

1011 return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
1012
1013 def find_elements(self, by: str | By | RelativeBy = By.ID, value: str | None = None) -> list[WebElement]:
1014 """Find elements given a By strategy and locator.
1015
1016 Args:
1017 by: The locating strategy to use. Default is `By.ID`. Supported
1018 values include: By.ID, By.NAME, By.XPATH, By.CSS_SELECTOR,
1019 By.CLASS_NAME, By.TAG_NAME, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,
1020 or RelativeBy.
1021 value: The locator value to use with the specified `by` strategy.
1022
1023 Returns:
1024 List of WebElements matching locator strategy found on the page.
1025
1026 Example:
1027 `element = driver.find_elements(By.ID, 'foo')`
1028 """
1029 by, value = self.locator_converter.convert(by, value)
1030
1031 if isinstance(by, RelativeBy):
1032 return self._find_elements_relative(by)
1033
1034 # Return empty list if driver returns null
1035 # See https://github.com/SeleniumHQ/selenium/issues/4555
1036 return self.execute(Command.FIND_ELEMENTS, {"using": by, "value": value})["value"] or []
1037
1038 def _find_elements_relative(self, by: RelativeBy, root: WebElement | ShadowRoot | None = None) -> list[WebElement]:
1039 """Find elements with a relative locator, searching from root, or the document when root is None."""

Callers 2

find_elementMethod · 0.95
mutation_eventsMethod · 0.45

Calls 3

executeMethod · 0.95
convertMethod · 0.45

Tested by

no test coverage detected