1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {"profile.default_content_setting_values.cookies": 1})
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
driver.get("https://connect.garmin.com/signin/") #loading page
wait = WebDriverWait(driver, 20) #defining webdriver wait
#defining username and password
username = 'mon_login'
password = 'mon_password\n' #\n will act as enter key
def login():
wait.until(EC.visibility_of_element_located((By.XPATH, "//iframe[@id='gauth-widget-frame-gauth-widget']")))
frameLogin = driver.find_element(By.XPATH, "//iframe[@id='gauth-widget-frame-gauth-widget']")
driver.switch_to.frame(frameLogin)
wait.until(EC.visibility_of_element_located((By.ID, 'username'))).send_keys(username) #userame/email
wait.until(EC.visibility_of_element_located((By.ID, 'password'))).send_keys(password) #password
time.sleep(5)
#try to click on reject cookies
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@class='truste_popframe']")))
frameCookies = driver.find_element_by_xpath("//iframe[@class='truste_popframe']")
driver.switch_to.frame(frameCookies)
wait.until(EC.visibility_of_element_located((By.XPATH, ".//a[@class='acceptAllButtonLower']"))).click()
login()
print('Url: ', driver.current_url) |
Partager