【发布时间】:2017-01-23 16:12:58
【问题描述】:
我有一种情况,我正在使用 selenium webdriver 测试一些东西。尝试登录 OneDrive 时,驱动程序会忽略所有等待,并且我收到“元素不可见错误”,特别是针对您输入密码的页面。这只发生在这种情况下,我使用几乎相同的代码在多个页面上运行登录过程的其余实例都可以正常工作。
这是失败代码对应的代码
def selenium_onedrive(loading_done_event, selenium, user, psw):
loading_done_event.wait()
login = selenium.find_elements_by_name('loginfmt')[0]
login.send_keys(user)
next_step = selenium.find_element_by_id('idSIButton9')
next_step.click()
password = WebDriverWait(selenium, 10).until(
# EC.presence_of_element_located((By.NAME, "passwd"))
EC.element_to_be_clickable((By.ID, "i0118"))
)
**password.send_keys(psw)**
# password.submit()
next_step = selenium.find_element_by_id('idSIButton9')
next_step.click()
粗线是出现错误的地方。它说找不到元素,但忽略了等待(甚至是隐式等待)。
这是一个有效的登录代码示例
def selenium_gdrive(loading_done_event, selenium, user, psw):
loading_done_event.wait()
login = selenium.find_elements_by_name('Email')[0]
login.send_keys(user)
selenium.find_elements_by_name('signIn')[0].click()
password = WebDriverWait(selenium, 10).until(
EC.presence_of_element_located((By.NAME, "Passwd"))
)
password.send_keys(psw)
password.submit()
# now we will be navigated to the consent page
consent_accept_button = WebDriverWait(selenium, 10).until(
EC.element_to_be_clickable((By.ID, "submit_approve_access"))
)
consent_accept_button.click()
附加信息,使用 Firefox 驱动程序运行代码。如果我使用 Chrome 版本,它运行良好,但不稳定并随机出现“远程连接结束”
【问题讨论】:
-
哪条线路负责?
-
在“password.send_keys(psw)”这一行中抛出错误,它表示找不到元素。它完全忽略了等待,即使我使用implicitly_wait()
标签: python selenium selenium-webdriver wait pytest