我尝试使用Selenium和python单击以下按钮:
<button type="submit" tabindex="4" id="sbmt" name="_eventId_proceed">
Einloggen
</button>
这只是一个简单的按钮,看起来像这样:
代码:
^{pr2}$这将导致以下异常:
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测试了它。在
我怎样才能在没有异常的情况下点击按钮?在
任何帮助都将不胜感激
要在元素上调用
click()
,首先需要将WebDriverWait与expected_conditions
一起使用,以便元素可以单击,您可以使用以下解决方案:使用
XPATH
:注意:您必须添加以下导入:
相关问题 更多 >
编程相关推荐