1

I am not able to select "Event" in following code using text().

<a class="atg-p-8" href="https://www.abc.com">
            <span class="atg-mr-12">... </span>
              " Event
               "
</a>

This is the Xpath that I'm using:- ( .//a/span[text() ='Event'] )

1
  • The span text is ... - "Event" is outside the span. You may also need to use a contains or partial link text function if the spacing between the word and the quotation marks is accurate. – Kate Paulk Mar 8 at 12:29
1
//a[text()[contains(.,'Event')]]

the tag have two text node so you have to use the above locator , this checks if any text node of a has Event in it

you can also use:

//a[contains(string(),'Event')]

This will convert all text node to string and then search event in it

1

You can try as following

driver.find_elements_by_xpath("//*[contains(text(), 'Event')]")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.