Skip to content

Commit

Permalink
Merge pull request #85 from smkent/fix-stale-element-reference-except…
Browse files Browse the repository at this point in the history
…ion-in-sign-in-result

Ignore `StaleElementReferenceException` in `_sign_in_success`
  • Loading branch information
smkent authored Jul 10, 2023
2 parents 10e4d38 + 29a8d42 commit 335b131
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions safeway_coupons/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import requests
import selenium.webdriver.support.expected_conditions as ec
import undetected_chromedriver as uc # type: ignore
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import (
StaleElementReferenceException,
TimeoutException,
)
from selenium.webdriver.remote.webdriver import By
from selenium.webdriver.support.wait import WebDriverWait

Expand Down Expand Up @@ -59,12 +62,15 @@ def __init__(self, account: Account, debug_dir: Optional[Path]) -> None:

@staticmethod
def _sign_in_success(driver: ec.AnyDriver) -> bool:
element = driver.find_element(
By.XPATH, '//span [contains(@class, "user-greeting")]'
)
if not (element and element.text):
try:
element = driver.find_element(
By.XPATH, '//span [contains(@class, "user-greeting")]'
)
if not (element and element.text):
return False
return not element.text.lower().startswith("sign in")
except StaleElementReferenceException:
return False
return not element.text.lower().startswith("sign in")

def _login(self, account: Account) -> None:
options = uc.ChromeOptions()
Expand Down

0 comments on commit 335b131

Please sign in to comment.