在python 3.6中使用selenium web驱动程序尝试自动化Web登录时出错

时间:2017-09-16 15:00:15

标签: selenium-webdriver python-3.6

以下是我的代码并且仅在某些时候出现此错误。令人惊讶的是,当我逐行运行相同的代码时,它按预期工作!

from selenium import webdriver
browser=webdriver.Chrome()
browser.maximize_window()
browser.get('https://www.gmail.com')
email=browser.find_element_by_xpath('//*[@id="identifierId"]')
email.send_keys('my email-id')
next=browser.find_element_by_xpath('//*[@id="identifierNext"]/content/span')
next.click()
browser.implicitly_wait(9)
passwd=browser.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
passwd.send_keys('mypassword')
next1=browser.find_element_by_xpath('//*[@id="passwordNext"]/content/span')
next1.click()

错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Element <span class="RveJvd snByac">...</span> is not clickable at point (942, 426). Other element would receive the click: <div class="
ANuIbb IdAqtf" jsname="k4HEge" tabindex="0"></div>
  (Session info: chrome=61.0.3163.91)
  (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.1.7601 SP1 x86_64)

2 个答案:

答案 0 :(得分:0)

希望你的问题能够得到解决

{{1}}

答案 1 :(得分:0)

下面的代码应该适合你。基本思想是等待密码字段,直到它在DOM中准备好

from selenium import webdriver
browser=webdriver.Chrome()
browser.maximize_window()
browser.get('https://www.gmail.com')
email=browser.find_element_by_xpath('//*[@id="identifierId"]')
email.send_keys('my email-id')
next=browser.find_element_by_xpath('//*[@id="identifierNext"]/content/span')
next.click()
passwd=browser.find_element_by_xpath("//input[@name='password']")
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable(passwd))
passwd.send_keys('mypassword')
next1=browser.find_element_by_xpath('//*[@id="passwordNext"]/content/span')
next1.click()