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

Method find_elements

py/selenium/webdriver/remote/webdriver.py:913–942  ·  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

911 return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
912
913 def find_elements(self, by: str | By | RelativeBy = By.ID, value: str | None = None) -> list[WebElement]:
914 """Find elements given a By strategy and locator.
915
916 Args:
917 by: The locating strategy to use. Default is `By.ID`. Supported
918 values include: By.ID, By.NAME, By.XPATH, By.CSS_SELECTOR,
919 By.CLASS_NAME, By.TAG_NAME, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,
920 or RelativeBy.
921 value: The locator value to use with the specified `by` strategy.
922
923 Returns:
924 List of WebElements matching locator strategy found on the page.
925
926 Example:
927 `element = driver.find_elements(By.ID, 'foo')`
928 """
929 by, value = self.locator_converter.convert(by, value)
930
931 if isinstance(by, RelativeBy):
932 _pkg = ".".join(__name__.split(".")[:-1])
933 raw_data = pkgutil.get_data(_pkg, "findElements.js")
934 if raw_data is None:
935 raise FileNotFoundError(f"Could not find findElements.js in package {_pkg}")
936 raw_function = raw_data.decode("utf8")
937 find_element_js = f"/* findElements */return ({raw_function}).apply(null, arguments);"
938 return self.execute_script(find_element_js, by.to_dict())
939
940 # Return empty list if driver returns null
941 # See https://github.com/SeleniumHQ/selenium/issues/4555
942 return self.execute(Command.FIND_ELEMENTS, {"using": by, "value": value})["value"] or []
943
944 @property
945 def capabilities(self) -> dict:

Calls 7

execute_scriptMethod · 0.95
executeMethod · 0.95
splitMethod · 0.80
get_dataMethod · 0.80
decodeMethod · 0.65
convertMethod · 0.45
to_dictMethod · 0.45