雅虎使用Selenium登录,缺少点击 [英] Yahoo sign in with Selenium, missing click

查看:134
本文介绍了雅虎使用Selenium登录,缺少点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写登录功能.当我尝试登录到我的yahoo帐户时,我会为我的电子邮件地址发送正确的密钥,该密钥可以正常工作,但是当我单击下一步"时,它错过了"点击,而是单击了横幅,从而打开了某种广告它与旅行有关或诺顿反安全等等.在过去的一周中,我一直在间歇性地研究此问题,直到最终发表我的第一篇文章为止.

I am trying to write a login function. When I try to login into my yahoo account, I send the correct keys for my email address, which works, but then when I click "next" it 'misses' the click and instead clicks the banner which opens up some sort of advertisement be it travel related or Norton anti-security, or something. I've been working on this issue intermittently throughout the past week surfing and digging through forums before finally making my first post.

我知道通过css,id,类名,xpath等进行元素选择器的不同方式.我尝试过sleep(),implicit_wait()以及类似的方法.我也尝试了一些尝试,直到可以从selenium.webdriver中的预期条件模块中单击.

I am aware of the different ways of element selectors via css, id, class name, xpath, etc... I tried sleep(), implicit_wait(), things along those lines. I also tried something with wait until clickable with the expected conditions module from selenium.webdriver.

我已附上一张到目前为止的图片.我的python版本是最新的,我的selenium和chrome驱动程序安装也是最新的.我已经看到过类似的帖子,但是OP似乎没有遇到我的问题. (如何点击雅虎使用Selenium Web驱动程序登录链接吗?)

I've attached an image of what I have so far. My python version is up-to-date as are my selenium and chrome driver installations. I saw a similar post already up, but the OP didn't seem to be encountering my issue. (how to click on the yahoo sign in link using selenium web driver?)

我也尝试过,它打开了广告;在我的处决中,诺顿似乎是最常出现的广告. (使用Python Selenium登录到Yahoo )

I tried this as well, and it opens the advertisement; in my executions, Norton seems to be the most frequently appearing advertisement. (login to Yahoo using Python Selenium)

我看过API文档,但是关于我可以做什么似乎没有明确的方向.我已经附上了脚本运行以及我所拥有的代码后的屏幕截图.

I've looked at the API documentation, but there doesn't seem to be any clear direction on what I could do. I've attached screenshots of what happens on the running of the script as well as the code I have.

在某些运行中我可以使用它,我可以转到下一个表格发送密码,但这是随机且莫名其妙地发生的.

I got it to work for some runs where I was able to go to the next form to send my password keys, but it happened randomly and inexplicably.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from login import password, email
from time import sleep

class yahoo():

def __init__(self):

    # INITIALIZE CHROME WEBDRIVER
    self.driver = webdriver.Chrome()
    self.driver.maximize_window()

def login(self):

    # OPEN BROWSER TO LOGIN PAGE AND MAXIMIZE
    self.driver.get("https://login.yahoo.com/config/login?.\
    src=fpctx&.intl=us&.lang=en-US&.done=https://www.yahoo.com")
    # LOGIN ACTIONS

    {# 1. send email address and click next
    self.driver.find_element_by_id('login-username').send_keys(email)
    element = WebDriverWait(self.driver, 10).until(\
            EC.presence_of_element_located((By.ID, "login-signin")))
    element.click()

    # 2. send password and click sign in
    self.driver.find_element_by_xpath('//*[@id="login-passwd"]').send_keys(password)
    self.driver.find_element_by_id('login-signin').click()}`enter code here




x = yfscreeners()
x.login()

我们非常感谢您的帮助.

Any help is well appreciated.

推荐答案

要将字符序列发送到电子邮件地址字段,并在按钮上调用click(),文本为 Next ,您需要为element_to_be_clickable()引入 WebDriverWait ,并且可以使用以下任一

To send a character sequence to the Email address field and invoke click() on the button with text as Next you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • 使用css_selector:

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

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')   
driver.get('https://login.yahoo.com')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.phone-no#login-username"))).send_keys('my_username@yahoo.co.in')
driver.find_element_by_css_selector("input#login-signin").submit()

  • 使用xpath:

    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
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')   
    driver.get('https://login.yahoo.com')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='phone-no ' and @id='login-username']"))).send_keys('my_username@yahoo.co.in')
    driver.find_element_by_xpath("//input[@id='login-signin']").submit()
    

  • 浏览器快照:

  • Browser Snapshot:

    这篇关于雅虎使用Selenium登录,缺少点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆