Find an element 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)
| 985 | _ = self.execute(Command.SET_TIMEOUTS, timeouts._to_json())["value"] |
| 986 | |
| 987 | def find_element(self, by: str | By | RelativeBy = By.ID, value: str | None = None) -> WebElement: |
| 988 | """Find an element given a By strategy and locator. |
| 989 | |
| 990 | Args: |
| 991 | by: The locating strategy to use. Default is `By.ID`. Supported |
| 992 | values include: By.ID, By.NAME, By.XPATH, By.CSS_SELECTOR, |
| 993 | By.CLASS_NAME, By.TAG_NAME, By.LINK_TEXT, By.PARTIAL_LINK_TEXT, |
| 994 | or RelativeBy. |
| 995 | value: The locator value to use with the specified `by` strategy. |
| 996 | |
| 997 | Returns: |
| 998 | The first matching WebElement found on the page. |
| 999 | |
| 1000 | Example: |
| 1001 | `element = driver.find_element(By.ID, 'foo')` |
| 1002 | """ |
| 1003 | by, value = self.locator_converter.convert(by, value) |
| 1004 | |
| 1005 | if isinstance(by, RelativeBy): |
| 1006 | elements = self.find_elements(by=by, value=value) |
| 1007 | if not elements: |
| 1008 | raise NoSuchElementException(f"Cannot locate relative element with: {by.root}") |
| 1009 | return elements[0] |
| 1010 | |
| 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. |