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

Method find_elements

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

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