Selenium登录到Yahoo

Selenium登录到Yahoo

本文介绍了使用Python Selenium登录到Yahoo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题实际上与该问题相同登录到使用Python Selenium网络驱动器的yahoo电子邮件帐户

My question actually is the same as this one login to yahoo email account using Python Selenium webdrive

但是,由于Yahoo更改了登录表单用户界面,因此上述链接中提供的答案对我不起作用.相反,我尝试了以下代码.

But since Yahoo has changed its login form UI, the answer provided in the above link doesn't work to me. Instead I tried the below code.

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

browser = webdriver.Firefox()
browser.get('https://login.yahoo.com')
emailElem = browser.find_element_by_id('login-username')
emailElem.send_keys('[email protected]')
emailElem.submit()

passwordElem = WebDriverWait(browser, 10).until(
    EC.presence_of_element_located((By.ID, "login-passwd"))
)
passwordElem.send_keys('thisismypassword')
passwordElem.submit()

wait = WebDriverWait(browser, 10)
wait.until(lambda browser: browser.current_url == "https://www.yahoo.com")
browser.get("https://mail.yahoo.com")

当我运行上面的代码时,它总是给我密码输入页面.我逐行执行了代码,我认为密码提交后的第二次等待不起作用.

When I run the above code,it always gives me the password input page. I executed the code line by line, I think the second wait after password submission didn't work.

在导航到Yahoo邮箱之前,需要您的建议如何在成功登录后将其更改为重定向到yahoo主页.谢谢!

Need your advice how to change it for redirecting to the yahoo main page on successful login before navigating to the Yahoo mail box. Thank you!

后续问题:@DebanjanB和@Nimish Bansal,非常感谢您的回答!我尝试过,您的答案都可以.我知道与我的代码的主要区别是将.submit()更改为.click().但为什么?摘自Selenium-Python文档( http://selenium-python.readthedocs .io/navigating.html#filling-in-forms ),两者的填写方式相同. 是否有任何引用详细说明.submit()和.click()之间的区别?谢谢.

Follow-up questions:@DebanjanB and @Nimish Bansal, Thanks a lot for your answers!I tried and both of your answers can work. I understand the key difference from my code is to change .submit() to .click(). But why? From the Selenium-Python document(http://selenium-python.readthedocs.io/navigating.html#filling-in-forms), both work in the same way for filling in forms. Any reference to elaborate the difference between .submit() and .click()? Thanks.

推荐答案

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

browser = webdriver.Chrome()
browser.get('https://login.yahoo.com')
emailElem = browser.find_element_by_id('login-username')
emailElem.send_keys('[email protected]')
loginbtn=browser.find_element_by_id("login-signin")
loginbtn.click()


passwordElem = WebDriverWait(browser, 10).until(
    EC.presence_of_element_located((By.ID, "login-passwd"))
)
passwordElem.send_keys('password')
submitBtn=browser.find_element_by_id("login-signin")
submitBtn.click()

让按钮仅通过单击即可完成其工作,而不是提交整个表单

Let the buttons do their job just by clicking instead of submitting the whole form

这篇关于使用Python Selenium登录到Yahoo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:33