|
13 | 13 | from apprise import Apprise
|
14 | 14 | from requests import Session
|
15 | 15 | from requests.adapters import HTTPAdapter
|
16 |
| -from selenium.common import NoSuchElementException, TimeoutException |
| 16 | +from selenium.common import NoSuchElementException, TimeoutException, ElementClickInterceptedException, \ |
| 17 | + ElementNotInteractableException |
17 | 18 | from selenium.webdriver.chrome.webdriver import WebDriver
|
18 | 19 | from selenium.webdriver.common.by import By
|
19 | 20 | from selenium.webdriver.remote.webelement import WebElement
|
@@ -175,30 +176,29 @@ def tryDismissAllMessages(self) -> None:
|
175 | 176 | (By.ID, "iNext"),
|
176 | 177 | (By.ID, "iLooksGood"),
|
177 | 178 | (By.ID, "idSIButton9"),
|
178 |
| - (By.CSS_SELECTOR, ".ms-Button.ms-Button--primary"), |
179 | 179 | (By.ID, "bnp_btn_accept"),
|
180 | 180 | (By.ID, "acceptButton"),
|
181 | 181 | ]
|
182 | 182 | for button in buttons:
|
183 | 183 | try:
|
184 | 184 | elements = self.webdriver.find_elements(by=button[0], value=button[1])
|
185 |
| - except NoSuchElementException: # Expected? |
| 185 | + except (NoSuchElementException, ElementNotInteractableException): # Expected? |
186 | 186 | logging.debug("", exc_info=True)
|
187 | 187 | continue
|
188 | 188 | for element in elements:
|
189 | 189 | element.click()
|
| 190 | + self.tryDismissCookieBanner() |
| 191 | + self.tryDismissBingCookieBanner() |
190 | 192 |
|
191 | 193 | def tryDismissCookieBanner(self) -> None:
|
192 |
| - with contextlib.suppress(NoSuchElementException): # Expected |
| 194 | + with contextlib.suppress(NoSuchElementException, ElementNotInteractableException): # Expected |
193 | 195 | self.webdriver.find_element(By.ID, "cookie-banner").find_element(
|
194 | 196 | By.TAG_NAME, "button"
|
195 | 197 | ).click()
|
196 |
| - time.sleep(2) |
197 | 198 |
|
198 | 199 | def tryDismissBingCookieBanner(self) -> None:
|
199 |
| - with contextlib.suppress(NoSuchElementException): # Expected |
| 200 | + with contextlib.suppress(NoSuchElementException, ElementNotInteractableException): # Expected |
200 | 201 | self.webdriver.find_element(By.ID, "bnp_btn_accept").click()
|
201 |
| - time.sleep(2) |
202 | 202 |
|
203 | 203 | def switchToNewTab(self, timeToWait: float = 0) -> None:
|
204 | 204 | time.sleep(0.5)
|
@@ -235,3 +235,10 @@ def saveBrowserConfig(sessionPath: Path, config: dict) -> None:
|
235 | 235 | configFile = sessionPath / "config.json"
|
236 | 236 | with open(configFile, "w") as f:
|
237 | 237 | json.dump(config, f)
|
| 238 | + |
| 239 | + def click(self, element: WebElement) -> None: |
| 240 | + try: |
| 241 | + element.click() |
| 242 | + except ElementClickInterceptedException: |
| 243 | + self.tryDismissAllMessages() |
| 244 | + element.click() |
0 commit comments