Skip to content

Instantly share code, notes, and snippets.

@J-Swift
Created September 8, 2024 15:42
Show Gist options
  • Save J-Swift/fdcb395a62e186fdebb8f0989f4620d3 to your computer and use it in GitHub Desktop.
Save J-Swift/fdcb395a62e186fdebb8f0989f4620d3 to your computer and use it in GitHub Desktop.
Selenium driver automation to automate chase offer redemptions
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
timeout_secs = 3
selector_add_btn = 'mds-icon[type="ico_add_circle"]'
selector_back_btn_shadow_root = 'mds-navigation-bar'
selector_back_btn_el = '#back-button'
options = webdriver.ChromeOptions()
options.debugger_address = "127.0.0.1:9222"
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(timeout_secs)
actions = ActionChains(driver)
wait = WebDriverWait(driver, timeout_secs)
while True:
element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, selector_add_btn)))
actions.move_to_element(element).click().perform()
shadow_host = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, selector_back_btn_shadow_root)))
element = driver.execute_script("return arguments[0].shadowRoot.querySelector('{}')".format(selector_back_btn_el), shadow_host)
actions.move_to_element(element).click().perform()
@J-Swift
Copy link
Author

J-Swift commented Sep 8, 2024

Start browser with

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=./data-dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment