Skip to content

Commit 263dca6

Browse files
authored
Fix ElementNotInteractableException (#176)
2 parents afd57db + 7b345e4 commit 263dca6

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.1] - 2024-08-13
9+
10+
### Fixed
11+
12+
- [Fix ElementNotInteractableException](https://github.com/klept0/MS-Rewards-Farmer/pull/176)
13+
814
## [0.2.0] - 2024-08-09
915

1016
### Added

src/activities.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ def __init__(self, browser: Browser):
1313

1414
def openDailySetActivity(self, cardId: int):
1515
# Open the Daily Set activity for the given cardId
16-
self.webdriver.find_element(
17-
By.XPATH,
18-
f'//*[@id="daily-sets"]/mee-card-group[1]/div/mee-card[{cardId}]/div/card-content/mee-rewards-daily-set-item-content/div/a',
19-
).click()
16+
element = self.webdriver.find_element(By.XPATH,
17+
f'//*[@id="daily-sets"]/mee-card-group[1]/div/mee-card[{cardId}]/div/card-content/mee-rewards-daily-set-item-content/div/a', )
18+
self.browser.utils.click(element)
2019
self.browser.utils.switchToNewTab(timeToWait=8)
2120

2221
def openMorePromotionsActivity(self, cardId: int):
2322
# Open the More Promotions activity for the given cardId
24-
self.webdriver.find_element(By.CSS_SELECTOR,
25-
f"#more-activities > .m-card-group > .ng-scope:nth-child({cardId + 1}) .ds-card-sec").click()
23+
element = self.webdriver.find_element(By.CSS_SELECTOR,
24+
f"#more-activities > .m-card-group > .ng-scope:nth-child({cardId + 1}) .ds-card-sec")
25+
self.browser.utils.click(element)
2626
self.browser.utils.switchToNewTab(timeToWait=5)
2727

2828
def completeSearch(self):

src/searches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def bingSearch(self) -> None:
170170
By.ID, "sb_form_q", timeToWait=20
171171
)
172172
for _ in range(1000):
173-
searchbar.click()
173+
self.browser.utils.click(searchbar)
174174
searchbar.clear()
175175
term = next(termsCycle)
176176
logging.debug(f"term={term}")

src/utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from apprise import Apprise
1414
from requests import Session
1515
from requests.adapters import HTTPAdapter
16-
from selenium.common import NoSuchElementException, TimeoutException
16+
from selenium.common import NoSuchElementException, TimeoutException, ElementClickInterceptedException, \
17+
ElementNotInteractableException
1718
from selenium.webdriver.chrome.webdriver import WebDriver
1819
from selenium.webdriver.common.by import By
1920
from selenium.webdriver.remote.webelement import WebElement
@@ -175,30 +176,29 @@ def tryDismissAllMessages(self) -> None:
175176
(By.ID, "iNext"),
176177
(By.ID, "iLooksGood"),
177178
(By.ID, "idSIButton9"),
178-
(By.CSS_SELECTOR, ".ms-Button.ms-Button--primary"),
179179
(By.ID, "bnp_btn_accept"),
180180
(By.ID, "acceptButton"),
181181
]
182182
for button in buttons:
183183
try:
184184
elements = self.webdriver.find_elements(by=button[0], value=button[1])
185-
except NoSuchElementException: # Expected?
185+
except (NoSuchElementException, ElementNotInteractableException): # Expected?
186186
logging.debug("", exc_info=True)
187187
continue
188188
for element in elements:
189189
element.click()
190+
self.tryDismissCookieBanner()
191+
self.tryDismissBingCookieBanner()
190192

191193
def tryDismissCookieBanner(self) -> None:
192-
with contextlib.suppress(NoSuchElementException): # Expected
194+
with contextlib.suppress(NoSuchElementException, ElementNotInteractableException): # Expected
193195
self.webdriver.find_element(By.ID, "cookie-banner").find_element(
194196
By.TAG_NAME, "button"
195197
).click()
196-
time.sleep(2)
197198

198199
def tryDismissBingCookieBanner(self) -> None:
199-
with contextlib.suppress(NoSuchElementException): # Expected
200+
with contextlib.suppress(NoSuchElementException, ElementNotInteractableException): # Expected
200201
self.webdriver.find_element(By.ID, "bnp_btn_accept").click()
201-
time.sleep(2)
202202

203203
def switchToNewTab(self, timeToWait: float = 0) -> None:
204204
time.sleep(0.5)
@@ -235,3 +235,10 @@ def saveBrowserConfig(sessionPath: Path, config: dict) -> None:
235235
configFile = sessionPath / "config.json"
236236
with open(configFile, "w") as f:
237237
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

Comments
 (0)