How to select third image in a page using Xpath or CSS

时间:2019-04-23 08:52:22

标签: selenium selenium-webdriver selenium-chromedriver

I would like to select the third image on the page using XPath or CSS.

I tried using the below command:

xpath=//img[@class='s-image'] 

1 个答案:

答案 0 :(得分:1)

使用[]引用instance的第n个元素。index从1而不是0开始。 [] 运算符的优先级(优先级)比 // 缩写更高。

xpath=(//img[@class='s-image'])[n]

您可以输入图像值而不是n。

当需要指定其选定节点列表的第N个节点时,始终将类型为'// Expression'的表达式放在方括号中。

检查this 链接以获取更多信息。