Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. QA Testing
  3. Question
QA Testing

I want to know what xpath text equals to?

Asked by Alex Gonzalez Apr 27, 2022 1.5K views 1 answer
Share

About this question

In the Flipkart page, I searched for Apple ipads and clicked on the first search result. Here, I wanted to click on 'BUY NOW'.

I used the following xpath and it worked:

//button[text()='BUY NOW'] Then I used the xpath with 'contains' but it didn't work: //button[contains(text(),'BUY NOW')]

Also this: //button[contains(text(),'BUY')]

But none worked. I was really surprised as to why 'contains' is not identifying the elements. I found the same behavior with the 'Add to Cart' button as well.

Then I tried to identify another element - 'Wi-Fi+4G' with contains and it worked:

//a[contains(text(),'Wi-Fi+4G')]

//a[text()='Wi-Fi+4G']

Both the above xpath worked for me.

So, can you please explain why 'contains' is not working here?

Your answer

1 Answer

More QA Testing discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest QA Testing Blogs

Guides, tips and career advice on QA Testing from JanBask experts.