Python 2.7 can';t单击selenium中的元素

Python 2.7 can';t单击selenium中的元素,python-2.7,selenium,selenium-webdriver,xpath,selenium-chromedriver,Python 2.7,Selenium,Selenium Webdriver,Xpath,Selenium Chromedriver,我正试图点击这个网站上包含电话号码的元素,链接如下。这是表示“卡通人物”的元素 查找元素非常简单: tel = driver.find_element_by_xpath("//button[contains(@title, 'telefoon')]") 但如果我想点击它,到目前为止我知道两种方法: tel.click() 这只返回ElementNotVisibleException。另一方面: driver.execute_script("arguments[0].click();"

我正试图点击这个网站上包含电话号码的元素,链接如下。这是表示“卡通人物”的元素



查找元素非常简单:

tel = driver.find_element_by_xpath("//button[contains(@title, 'telefoon')]")

但如果我想点击它,到目前为止我知道两种方法:

tel.click()
这只返回ElementNotVisibleException。另一方面:

driver.execute_script("arguments[0].click();", tel)
这没有任何作用,没有错误,也没有单击,因为信息不会显示。我还可以做些什么来成功点击这个?

试试这个:

phone_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@id='vip-seller']/following-sibling::section/child::button")))  
phone_button .click()  
确保您正在导入以下内容:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 

您编写的Xpath包含两个web元素。希望这会有所帮助。

要单击文本为Toon nummer的元素,您必须引导WebDriverWait使该元素可单击,您可以使用以下解决方案:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
# other lines of code
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//aside[@class='l-side-right']//button[@class='mp-Button mp-Button--secondary' and @title='Toon telefoonnummer']//span[contains(.,'Toon')]"))).click()

试试这个
驱动程序。通过css('.mp-Button.mp-Button--secondary')查找\u-element\u,然后告诉我谢谢,这似乎很有效。我没有意识到有两个元素与我的xpath搜索相对应。@DoctorEvil:没问题。这会导致NoTouchElementException现在超时。如果我尝试用xpath搜索,它不会找到任何元素。elements=driver.find_elements\u by_xpath(“//button[@class='mp-button mp button--secondary']///span[normalize-space()='Toon'])@DoctorEvil-Yup,my bad,
是使所需元素唯一的节点。更新了我的答案。