|
25 | 25 | from hashlib import md5 as md5_hash |
26 | 26 | from io import BytesIO |
27 | 27 |
|
28 | | -from selenium.common.exceptions import JavascriptException, WebDriverException |
| 28 | +from selenium.common.exceptions import InvalidSelectorException, JavascriptException, WebDriverException |
29 | 29 | from selenium.webdriver.common.by import By |
30 | 30 | from selenium.webdriver.common.utils import keys_to_typing |
31 | 31 |
|
@@ -598,7 +598,12 @@ def find_element(self, by=By.ID, value=None) -> WebElement: |
598 | 598 | WebElement |
599 | 599 | The first matching `WebElement` found on the page. |
600 | 600 | """ |
| 601 | + if by == "class name": |
| 602 | + if value and any(char.isspace() for char in value.strip()): |
| 603 | + raise InvalidSelectorException("Compound class names are not allowed.") |
| 604 | + |
601 | 605 | by, value = self._parent.locator_converter.convert(by, value) |
| 606 | + |
602 | 607 | return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"] |
603 | 608 |
|
604 | 609 | def find_elements(self, by=By.ID, value=None) -> list[WebElement]: |
@@ -627,7 +632,12 @@ def find_elements(self, by=By.ID, value=None) -> list[WebElement]: |
627 | 632 | List[WebElement] |
628 | 633 | list of `WebElements` matching locator strategy found on the page. |
629 | 634 | """ |
| 635 | + if by == "class name": |
| 636 | + if value and any(char.isspace() for char in value.strip()): |
| 637 | + raise InvalidSelectorException("Compound class names are not allowed.") |
| 638 | + |
630 | 639 | by, value = self._parent.locator_converter.convert(by, value) |
| 640 | + |
631 | 641 | return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})["value"] |
632 | 642 |
|
633 | 643 | def __hash__(self) -> int: |
|
0 commit comments