使用 Python Selenium webdriver 登录雅虎电子邮件帐户

login to yahoo email account using Python Selenium webdrive

我需要使用带有 Python 的 Selenium 登录雅虎电子邮件帐户。

这是我的代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("https://login.yahoo.com")

print driver.current_url

logintxt = driver.find_element_by_name("username")
logintxt.send_keys("email")

pwdtxt = driver.find_element_by_name("passwd")
pwdtxt.send_keys("pass")



button = driver.find_element_by_id("login-signin")
button.click()
driver.get("https://mail.yahoo.com")
print driver.current_url

但是当我打印当前url时,它总是给我登录页面,这意味着它没有登录。

知道如何解决吗? 我在 python 2.6

中使用 Centos 6

等待它(使用 WebDriverWait)将您重定向到成功登录后的 yahoo 主页,然后再导航到 Yahoo 邮箱:

from selenium.webdriver.support.wait import WebDriverWait

button = driver.find_element_by_id("login-signin")
button.click()

# give it time to log in
wait = WebDriverWait(driver, 10)
wait.until(lambda driver: driver.current_url == "https://www.yahoo.com/")

driver.get("https://mail.yahoo.com")