【发布时间】:2019-05-31 20:44:53
【问题描述】:
我正在尝试使用 Selenium 和 python 单击以下按钮:
<button type="submit" tabindex="4" id="sbmt" name="_eventId_proceed">
Einloggen
</button>
这只是一个简单的按钮,如下所示:
代码:
driver.find_element_by_id('sbmt').click()
这会导致以下异常:
selenium.common.exceptions.ElementNotInteractableException: Message:
Element <button id="sbmt" name="_eventId_proceed" type="submit">
could not be scrolledinto view
所以,我尝试在单击按钮之前使用 ActionChains(driver).move_to_element(driver.find_elements_by_id('sbmt')[1]).perform() 滚动到元素。
(使用[1] 访问第二个元素,因为第一个元素会导致selenium.common.exceptions.WebDriverException: Message: TypeError: rect is undefined 异常。)。
然后我用了
wait = WebDriverWait(driver, 5)
submit_btn = wait.until(EC.element_to_be_clickable((By.ID, 'sbmt')))
为了等待按钮可点击。这些都没有帮助。
我也用过driver.find_element_by_xpath等,我用Firefox和Chrome测试过。
如何点击按钮而不出现异常?
任何帮助将不胜感激
【问题讨论】:
标签: python selenium selenium-webdriver