如何使用Selenium Python单击按钮 [英] How to click the button using selenium python
问题描述
I'm new to Python and Selenium and I want to click the button "Afficher plus" in this url.
我已经尝试过此代码:
plus = driver.find_element_by_css_selector("button[class='b-btn b-
ghost']")
plus.click()
但它不起作用,并且出现此错误:
but it doesn't work and i get this error:
selenium.common.exceptions.WebDriverException:消息:未知错误:元素...在点(390,581)处不可单击.其他元素将获得点击:...
selenium.common.exceptions.WebDriverException: Message: unknown error: Element ... is not clickable at point (390, 581). Other element would receive the click: ...
推荐答案
您尝试单击的元素不可点击,或者可能重叠.
Element you are trying to click is not clickable, or might be overlapped.
尝试通过执行Java脚本单击功能来单击指定的元素.
Try to click specified element, by executing java script click function.
driver.execute_script("arguments[0].click();", element)
另一方面,您的页面可能尚未完全加载,因此元素可能尚未可单击,您可以使用等待条件:
On another hand, your page might not yet be fully loaded, so element might not be clickable yet, you can use wait for condition:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable(By...)) //change selector
element.click();
这篇关于如何使用Selenium Python单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!