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

标签 python selenium selenium-webdriver automation yahoo

我需要使用 Selenium 和 Python 登录 yahoo 电子邮件帐户。

这是我的代码

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

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

知道如何修复它吗? 我使用 Centos 6 和 python 2.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")

关于python - 使用 Python Selenium webdriver 登录雅虎电子邮件帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31945947/

相关文章:

python 名称错误 : global name '__file__' is not defined

python - 3D 矩阵元素与 2D 矩阵副本的高效逐元素乘法?

java - 我收到以下代码的 "java.lang.Exception: Method tearDown should have no parameters"& result.getStatus 为 null

javascript - Selenium click 不适用于 angularjs ng-click 事件

java - WebDriver 无法使用 HotMail https 找到元素

java - Selenium 网络驱动程序 : cannot be scrolled into view

python - 使用 python 字典和列表元素创建列表项

python - 在 Plotly 气泡图中标记特定气泡

java - Selenium:无法选择下拉菜单

http - 在 Python 中将 Firefox WebDriver 与 Selenium 连接时出现问题