Find elements inside a shadow root given a By strategy and locator. Args: by: The locating strategy to use. Default is `By.ID`. Supported values include: - By.ID: Locate by element ID. - By.NAME: Locate by the `name` attribute. - B
(self, by: str | By = By.ID, value: str | None = None)
| 88 | return self._execute(Command.FIND_ELEMENT_FROM_SHADOW_ROOT, {"using": by, "value": value})["value"] |
| 89 | |
| 90 | def find_elements(self, by: str | By = By.ID, value: str | None = None) -> list[WebElement]: |
| 91 | """Find elements inside a shadow root given a By strategy and locator. |
| 92 | |
| 93 | Args: |
| 94 | by: The locating strategy to use. Default is `By.ID`. Supported values include: |
| 95 | - By.ID: Locate by element ID. |
| 96 | - By.NAME: Locate by the `name` attribute. |
| 97 | - By.XPATH: Locate by an XPath expression. |
| 98 | - By.CSS_SELECTOR: Locate by a CSS selector. |
| 99 | - By.CLASS_NAME: Locate by the `class` attribute. |
| 100 | - By.TAG_NAME: Locate by the tag name (e.g., "input", "button"). |
| 101 | - By.LINK_TEXT: Locate a link element by its exact text. |
| 102 | - By.PARTIAL_LINK_TEXT: Locate a link element by partial text match. |
| 103 | value: The locator value to use with the specified `by` strategy. |
| 104 | |
| 105 | Returns: |
| 106 | List of `WebElements` matching locator strategy found on the page. |
| 107 | |
| 108 | Example: |
| 109 | >>> element = driver.find_elements(By.ID, "foo") |
| 110 | """ |
| 111 | if by == By.ID: |
| 112 | by = By.CSS_SELECTOR |
| 113 | value = f'[id="{value}"]' |
| 114 | elif by == By.CLASS_NAME: |
| 115 | if value and any(char.isspace() for char in value.strip()): |
| 116 | raise InvalidSelectorException("Compound class names are not allowed.") |
| 117 | by = By.CSS_SELECTOR |
| 118 | value = f".{value}" |
| 119 | elif by == By.NAME: |
| 120 | by = By.CSS_SELECTOR |
| 121 | value = f'[name="{value}"]' |
| 122 | |
| 123 | return self._execute(Command.FIND_ELEMENTS_FROM_SHADOW_ROOT, {"using": by, "value": value})["value"] |
| 124 | |
| 125 | # Private Methods |
| 126 | def _execute(self, command, params=None): |
nothing calls this directly
no test coverage detected