Yahoo 使用 Selenium 登录,缺少点击
·
问题:Yahoo 使用 Selenium 登录,缺少点击
我正在尝试编写登录功能。当我尝试登录我的雅虎帐户时,我为我的电子邮件地址发送了正确的密钥,这有效,但是当我点击“下一步”时,它“错过”了点击,而是点击了打开某种广告的横幅它与旅行有关或诺顿反安全,或什么的。在过去的一周里,我一直在断断续续地研究这个问题,在最终发表我的第一篇文章之前浏览和挖掘论坛。
我知道元素选择器通过 css、id、类名、xpath 等的不同方式......我尝试了 sleep()、implicit_wait() 等。我还尝试了使用 selenium.webdriver 中的预期条件模块等待直到可点击的方法。
我附上了一张我到目前为止所拥有的图片。我的 python 版本是最新的,我的 selenium 和 chrome 驱动程序安装也是如此。我已经看到了类似的帖子,但是 OP 似乎没有遇到我的问题。 (如何使用 selenium 网络驱动程序点击 yahoo 登录链接?)
我也试过了,它打开了广告;在我的处决中,诺顿似乎是出现频率最高的广告。 (使用 Python Selenium 登录 Yahoo)
我查看了 API 文档,但似乎没有明确的方向说明我能做什么。我附上了脚本运行时发生的屏幕截图以及我拥有的代码。
我让它在一些运行中工作,在那里我能够转到下一个表单来发送我的密码密钥,但它是随机且莫名其妙地发生的。
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()
任何帮助都将不胜感激。
解答
要将字符序列发送到 Email 地址 字段并在按钮上调用click()
,文本为 Next 您需要为element_to_be_clickable()
诱导 WebDriverWait ,您可以使用以下任一定位器策略:
- 使用
css_selector
:
从硒导入网络驱动程序
从 selenium.webdriver.common.by 导入
从 selenium.webdriver.support.ui 导入 WebDriverWait
从 selenium.webdriver.support 导入 expected_conditions 作为 EC
选项 u003d webdriver.ChromeOptions()
options.add_argument("开始最大化")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver u003d webdriver.Chrome(optionsu003doptions, executable_pathu003dr'C:\Utility\BrowserDriver
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
:
从硒导入网络驱动程序
从 selenium.webdriver.common.by 导入
从 selenium.webdriver.support.ui 导入 WebDriverWait
从 selenium.webdriver.support 导入 expected_conditions 作为 EC
选项 u003d webdriver.ChromeOptions()
options.add_argument("开始最大化")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver u003d webdriver.Chrome(optionsu003doptions, executable_pathu003dr'C:\Utility\BrowserDriver
driver.get('https://login.yahoo.com')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@classu003d'phone-no' and @idu003d'login-username']")))).send_keys('my_username @yahoo.co.in')
driver.find_element_by_xpath("//input[@idu003d'login-signin']").submit()
- 浏览器快照:
更多推荐
所有评论(0)