Python 使用selenium的google帐户登录自动化导致错误

Python 使用selenium的google帐户登录自动化导致错误,python,selenium,error-handling,automation,google-signin,Python,Selenium,Error Handling,Automation,Google Signin,我正在尝试用selenium登录Google。步骤很简单,首先键入email并点击next,然后键入password并点击next。我的代码如下所示: driver = webdriver.Firefox() driver.get("https://accounts.google.com/signin") driver.implicitly_wait(3) driver.find_element_by_id("identifierId").send_keys("email") driver.

我正在尝试用selenium登录Google。步骤很简单,首先键入email并点击next,然后键入password并点击next。我的代码如下所示:

driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

driver.implicitly_wait(8)
password = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@type='password']")))
password = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@type='password']")))

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
代码的第一部分(电子邮件部分)工作得很好。我还检查了最后一部分(在编写密码后点击next),它也非常有效。唯一的问题是密码。当我尝试执行密码。发送密钥(“密码”)时,会导致以下错误:

TypeError: object of type 'FirefoxWebElement' has no len()

有什么建议吗?

问题是,我只需等待加载密码presence和visibility,如下所示:

driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

driver.implicitly_wait(8)
password = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@type='password']")))
password = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@type='password']")))

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)

问题是,我只需等待密码presence和visibility加载,如下所示:

driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

driver.implicitly_wait(8)
password = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@type='password']")))
password = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@type='password']")))

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)