I couldn't choose (click) the element that in the title and the pic:

enter image description here

The element is one row in a table.

Here is the element :

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

I tried that:

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

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

That is the error I got:

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/[email protected]{#29}),platform=Linux 4.15.0-47-generic x86_64)

1 Answers

0
Kajal Kundu On

The tag you have provided is wrong not button it is span.

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

I would suggest use WebdriverWait and element_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()