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?