-4

I have following HTML:

<pre>
<div class="selected_text">
   <span class="memo">
   <span class="title">01.</span>I want This
   </span>
   <span class="blank"></span>
   <span class="price">
   100
   </span>
</div>
<pre>

I want to find the string that contains text I want this and click it.

So I try to use

driver.find_element_by_xpath('//span[contains(text(),"want")]').click()

But It's not working

How can i perform click on this element ?

NarendraR
  • 7,577
  • 10
  • 44
  • 82
Gilb
  • 1
  • 1
  • 1
    Does this answer your question? [How do I find an element that contains specific text in Selenium Webdriver (Python)?](https://stackoverflow.com/questions/12323403/how-do-i-find-an-element-that-contains-specific-text-in-selenium-webdriver-pyth) – deadshot Jun 15 '20 at 08:40
  • What do you mean by click it? The html you have give inst a clickable element. – Chris Doyle Jun 15 '20 at 08:40
  • Agree with @ChrisDoyle, the HTML you given seems `not clickable`. So you first check for `clickability` – Shivam Bharadwaj Jun 15 '20 at 08:47
  • 1
    @Gilb _But It's not working_, what error do you see? – undetected Selenium Jun 15 '20 at 08:48
  • @DebanjanB when I try to "driver.find_element_by_xpath('//span').get_attribute("text")", not response... "driver.find_element_by_xpath('//span/span').get_attribute("text")" -> '01' //Sorry for not explaining well in English. – Gilb Jun 15 '20 at 08:59
  • but "driver.find_element_by_xpath('//span[contains(text(),"01")]').click()" is worked. I want to click using "I want This" – Gilb Jun 15 '20 at 09:01

1 Answers1

0

Seems there is an issue with your xpath. Use . instead of text() in contains method. Refer this answer to identify difference between them.

Use explicit wait to avoid unnecessary timeout related things.

Refer below code :

WebDriverWait(driver, 45).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(.,'I want This')]"))).click()
NarendraR
  • 7,577
  • 10
  • 44
  • 82