|
1 | 1 | import functools |
2 | 2 | import time |
3 | 3 | import warnings |
| 4 | +from typing import Optional |
4 | 5 |
|
5 | 6 | import tldextract |
6 | 7 | from parsel.selector import Selector, SelectorList |
@@ -90,31 +91,31 @@ def is_cookie_in_driver(self, cookie) -> bool: |
90 | 91 | return True |
91 | 92 | return False |
92 | 93 |
|
93 | | - def ensure_element_by_id(self, selector, state="present", timeout=None) -> WebElement | None: |
| 94 | + def ensure_element_by_id(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
94 | 95 | return self.ensure_element(By.ID, selector, state, timeout) |
95 | 96 |
|
96 | | - def ensure_element_by_name(self, selector, state="present", timeout=None) -> WebElement | None: |
| 97 | + def ensure_element_by_name(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
97 | 98 | return self.ensure_element(By.NAME, selector, state, timeout) |
98 | 99 |
|
99 | | - def ensure_element_by_xpath(self, selector, state="present", timeout=None) -> WebElement | None: |
| 100 | + def ensure_element_by_xpath(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
100 | 101 | return self.ensure_element(By.XPATH, selector, state, timeout) |
101 | 102 |
|
102 | | - def ensure_element_by_link_text(self, selector, state="present", timeout=None) -> WebElement | None: |
| 103 | + def ensure_element_by_link_text(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
103 | 104 | return self.ensure_element(By.LINK_TEXT, selector, state, timeout) |
104 | 105 |
|
105 | | - def ensure_element_by_partial_link_text(self, selector, state="present", timeout=None) -> WebElement | None: |
| 106 | + def ensure_element_by_partial_link_text(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
106 | 107 | return self.ensure_element(By.PARTIAL_LINK_TEXT, selector, state, timeout) |
107 | 108 |
|
108 | | - def ensure_element_by_tag_name(self, selector, state="present", timeout=None) -> WebElement | None: |
| 109 | + def ensure_element_by_tag_name(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
109 | 110 | return self.ensure_element(By.TAG_NAME, selector, state, timeout) |
110 | 111 |
|
111 | | - def ensure_element_by_class_name(self, selector, state="present", timeout=None) -> WebElement | None: |
| 112 | + def ensure_element_by_class_name(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
112 | 113 | return self.ensure_element(By.CLASS_NAME, selector, state, timeout) |
113 | 114 |
|
114 | | - def ensure_element_by_css_selector(self, selector, state="present", timeout=None) -> WebElement | None: |
| 115 | + def ensure_element_by_css_selector(self, selector, state="present", timeout=None) -> Optional[WebElement]: |
115 | 116 | return self.ensure_element(By.CSS_SELECTOR, selector, state, timeout) |
116 | 117 |
|
117 | | - def ensure_element(self, locator: str, selector: str, state: str = "present", timeout=None) -> WebElement | None: |
| 118 | + def ensure_element(self, locator: str, selector: str, state: str = "present", timeout=None) -> Optional[WebElement]: |
118 | 119 | """This method allows us to wait till an element appears or disappears in the browser |
119 | 120 |
|
120 | 121 | The webdriver runs in parallel with our scripts, so we must wait for it everytime it |
@@ -192,7 +193,7 @@ def css(self, *args, **kwargs) -> SelectorList[Selector]: |
192 | 193 | def re(self, *args, **kwargs) -> list[str]: |
193 | 194 | return self.selector.re(*args, **kwargs) |
194 | 195 |
|
195 | | - def re_first(self, *args, **kwargs) -> str | None: |
| 196 | + def re_first(self, *args, **kwargs) -> Optional[str]: |
196 | 197 | return self.selector.re_first(*args, **kwargs) |
197 | 198 |
|
198 | 199 |
|
|
0 commit comments