I was practicing my x-path by clicking on YouTube videos trending section. On the trending section I want to click on second video present irrespective of whichever video is present. I have written below x-path to target the second video.
Below is the x-path using the text method.
//*[contains(text(),”1 day ago”)]
Now the above x-path targets all the 22 elements which contain the following text i.e. 1 day ago
My objective is to target the second video for that I have modified my x-path in the following way
//*[contains(text(),”1 day ago”)][2]
Now when I write this it does not select any elements at all below is the image
Image 1(View the rectangles I have marked in Red color)
However if I write //*[contains(text(),”1 day ago”)][1] it targets all the 22 elements which contains the following text. Below is the image
Image 2(View the rectangles I have marked in Red color)
I have two Questions
-
how should I modify my x-path so that it selects only the second element and why my current x-path i.e. //*[contains(text(),”1 day ago”)][2] is not working in the following scenario ??
-
When writing the following x-path //*[contains(text(),”1 day ago”)][1] why it is targeting all the 22 elements on the web page??
Thanks.