使用硒作为密码,完成Yahoo登录,然后单击“下一步”按钮

问题描述 投票:0回答:1

因此,我最初在此处发布了一个有关单击“下一步”以继续登录到我的Yahoo帐户的问题。 (原始帖子:Yahoo sign in with Selenium, missing click

我已经使用它并在过去的一个周末设法使用下面的代码登录,登录了我的帐户,但是今天,当我去向我的教授展示我的这个副项目时,登录无效,因为我的点击没有超过密码提交时间。我没有点击“下一步”来提交密码并完成登录,而是点击了表单框后面的广告。例如,下面附有图像,但这是原来起作用的代码:

def login(self):

    # SEND EMAIL KEYS
    WebDriverWait(self.driver, 3).until(EC.element_to_be_clickable(\
        (By.XPATH, "//input[@class='phone-no ' and @id='login-username']"))).send_keys(email)
    # CLICK NEXT
    self.driver.find_element_by_xpath("//input[@id='login-signin']").submit()
    self.driver.implicitly_wait(5)
    # SEND PASSWORD KEYS
    self.driver.implicitly_wait(5)
    WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable(\
        (By.XPATH, '//*[@id="login-passwd"]'))).send_keys(password)
    # CLICK NEXT
    WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(\
       (By.CSS_SELECTOR, '[class=button-container]'))).click()

相反,它单击广告而不是单击表单框上的按钮。最终打开了一个与广告相关的完全不同的选项卡,无论是Norton还是FreePass,等等...

我在他的办公时间里尝试修复它,但是没有一个起作用。我尝试了NAME,XPATH,CLASS,ID等...我可能会误称它们是哪一个,但是我又回过文档尝试不同的选择器,是的,正确地使用了它们。我也尝试了隐式等待,而不是使用ExpectedConditions类,但是没有一个起作用。

但是我尝试了以下代码:

def login(self):

    # SEND EMAIL KEYS
    WebDriverWait(self.driver, 3).until(EC.element_to_be_clickable(\
        (By.XPATH, "//input[@class='phone-no ' and @id='login-username']"))).send_keys(email)
    # CLICK NEXT
    self.driver.find_element_by_xpath("//input[@id='login-signin']").submit()
    self.driver.implicitly_wait(5)
    # SEND PASSWORD KEYS
    self.driver.implicitly_wait(5)
    WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable(\
        (By.XPATH, '//*[@id="login-passwd"]'))).send_keys(password)
    # CLICK NEXT
    self.driver.implicitly_wait(20)
    try:
        element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(\
                                                        (By.ID, 'login-signin')))
    finally:
        self.driver.quit()

    element.click()

然后我最终得到这个奇怪的异常:“ HTTPConnectionPool(host ='127.0.0.1',端口= 36561):URL超过了最大重试次数:/ session / 13fbff99fe85a470c34475fd6186b0cb / element / 23be378e-9643-4f16-8c74-7647e9d80ff8 / click(由NewConnectionError引起:(未能建立)一个新的连接:[Errno 111]连接被拒绝',))“

我不知道发生了什么。我最初的项目在家里非常出色,需要进行所有的点击和提交,然后抓取各种弹出窗口,但是现在不起作用了。我厌倦了在手机的热点上运行它,该热点比学校的校园无线和家庭无线都好,但是仍然无法正常工作,而是点击广告。

我也尝试过下面的代码片段,而不是等待可点击的等待元素:

 element = WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located(\
                                                        (By.ID, 'login-signin')))

这也不起作用,浏览器会打开和关闭,并给我同样的连接错误。

这可能与我的互联网连接有关吗?

观察我的密码密钥是否正确发送。 enter image description here

就在Linux上运行的chromedriver的更新驱动程序而言,其他所有条件都相同。截止到目前,倒数第二个版本的ubuntu。请帮忙,谢谢。我的python3是最新的linux支持的最新版本,而无需将计算机捣碎。

python selenium authentication connection webdriverwait
1个回答
0
投票

首先将字符序列发送到电子邮件地址字段,在按钮上调用文本为[[Next的click(),将字符序列发送到Password字段,然后再次调用[按钮上的文本为Next的C0],则需要为click()引入WebDriverWait,并且可以使用以下element_to_be_clickable()之一:

  • 使用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('[email protected]') driver.find_element_by_css_selector("input#login-signin").submit() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#password-container>input"))).send_keys('RichardYim') driver.execute_script("arguments[0].click();", driver.find_element_by_css_selector("button#login-signin"))

    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('[email protected]') driver.find_element_by_xpath("//input[@id='login-signin']").submit() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='password-container']/input"))).send_keys('RichardYim') driver.execute_script("arguments[0].click();", driver.find_element_by_xpath("//button[@id='login-signin']"))


    tl;医生

    yahoo_password_next

    © www.soinside.com 2019 - 2024. All rights reserved.