Python Selenium不允许我登录祖先



我已经使用selenium和chromedriver登录到ancestry.com,但是它说它没有找到登录信息的id。它打开浏览器,进入页面,填充并登录。我已经在其他网站上尝试过了,但它已经工作了,不知道为什么它不在这里工作。我试着让它睡几秒钟,认为页面需要完全加载(来自我的初学者知识)....代码如下,如果有人遇到麻烦或知道如何处理此登录,我将不胜感激。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
chrome_path= r"C:Users....chromedriver_win32chromedriver.exe"
driver= webdriver.Chrome(chrome_path)
driver.get("https://www.ancestry.com/account/signin")
sleep(15)
username= "username"
password= "password"
driver.find_element_by_id("username").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_id("signInBtn").click()
print("Logged in Successfully")

实际上,您需要切换到frame,我已经使用explicitWait而不是sleep

driver.get("https://www.ancestry.com/account/signin")
username= "username"
password= "password"
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_id("signInFrame")))
userName = WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.ID,"username")))
userName.send_keys(username)
passWord = WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.ID,"password")))
passWord.send_keys(password)
signIn = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"signInBtn")))
signIn.click()
print("Logged in Successfully")

最新更新