login to yahoo email account using Python Selenium webdrive

狂风中的少年 提交于 2019-12-24 03:53:12

问题


I need to login to yahoo email account using Selenium with Python.

this is my code

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

but when I print the current url, it always gives me the login page, which mean that it didn't login.

any idea about how to fix it ? I'm using Centos 6 with python 2.6


回答1:


Wait for it (using WebDriverWait) to redirect you to the yahoo main page on successful login before navigating to the Yahoo mail box:

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")


来源:https://stackoverflow.com/questions/31945947/login-to-yahoo-email-account-using-python-selenium-webdrive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!