Skip to content

Commit

Permalink
Merge pull request #86 from smkent/optional-cookie-prompt
Browse files Browse the repository at this point in the history
Skip cookie prompt if not present before starting sign in flow
  • Loading branch information
smkent authored Jul 10, 2023
2 parents 335b131 + 439ef42 commit e397a7c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions safeway_coupons/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import selenium.webdriver.support.expected_conditions as ec
import undetected_chromedriver as uc # type: ignore
from selenium.common.exceptions import (
NoSuchElementException,
StaleElementReferenceException,
TimeoutException,
)
Expand Down Expand Up @@ -93,12 +94,16 @@ def _login(self, account: Account) -> None:
url = "https://www.safeway.com"
print("Connect to safeway.com")
driver.get(url)
button = driver.find_element(
By.XPATH, "//button [contains(text(), 'Necessary Only')]"
)
if button:
print("Decline cookie prompt")
button.click()
try:
button = driver.find_element(
By.XPATH,
"//button [contains(text(), 'Necessary Only')]",
)
if button:
print("Decline cookie prompt")
button.click()
except NoSuchElementException:
print("Skipping cookie prompt which is not present")
print("Open Sign In sidebar")
wait.until(
ec.visibility_of_element_located(
Expand Down

0 comments on commit e397a7c

Please sign in to comment.