from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support import ui
capabilities = DesiredCapabilities.CHROME
capabilities["goog:loggingPrefs"] = {"performance": "ALL"} # chromedriver 75+
options = webdriver.ChromeOptions()
options.add_argument(f"user-data-dir={userdata_path}") #Path to your chrome profile
# options.add_experimental_option("excludeSwitches", ['enable-automation'])
# options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "safebrowsing-disable-download-protection", "safebrowsing-disable-auto-update", "disable-client-side-phishing-detection"])
driver = webdriver.Chrome(executable_path=webdriver_path, options=options)
driver.get("https://www.cbtnuggets.com/login")
logs = driver.get_log("performance")
def page_is_loaded(driver):
return driver.find_element_by_tag_name("body") != None
#wait=ui.WebDriverWait(driver,300)
driver.implicitly_wait(10)
#wait.until(page_is_loaded)
USERNAME = driver.find_element_by_xpath('//*[@id="email"]')
USERNAME.send_keys("johndoe@gmail.com")
PASSWORD = driver.find_element_by_xpath("/html/body/div[1]/div[2]/main/div/div[1]/form/fieldset/div[2]/input")
PASSWORD.send_keys("password")
Login_Button=driver.find_element_by_xpath("/html/body/div[1]/div[2]/main/div/div[1]/form/fieldset/button")
Login_Button.click()
driver.get("https://www.cbtnuggets.com/learn/it-training/playlist/nrn:playlist:user:5fcf88f463ebba00155acb18/2?autostart=1")
一切如期而至,但当最后一次
driver.get()
执行时,我会被返回到登录页面,但是当我在地址栏中手动输入第二个URL时,它可以正常工作,而不必再次登录。
我不知道这是一个硒问题,还是我误解了httpget的工作原理。