我在python硒中找不到以下元素

时间:2019-05-16 14:55:26

标签: python selenium

我无法选择(单击)标题和图片中的元素:

enter image description here

元素是表中的一行。

以下是元素:

<span _ngcontent-c37="" class="telno"> +529999111118 </span>

我尝试过:

number_element = driver.find_element_by_xpath("//button[contains(.,'+529999111118')]")

driver.execute_script("arguments[0].click();", number_element)

那是我得到的错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(.,'+549999111112')]"}
  (Session info: chrome=74.0.3729.131)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-47-generic x86_64)

1 个答案:

答案 0 :(得分:0)

您提供的标签不是button,而是span

number_element=driver.find_element_by_xpath("//span[contains(.,'+529999111118')]")
driver.execute_script("arguments[0].click();", number_element)

我建议使用WebdriverWaitelement_to_be_clickable

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

WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH,"//span[@class='telno'][contains(.,'+529999111118')]"))).click()