如何处理xpath、Selenium Webdriver、Java的变化
我试图在其他主题的基础上理解它,但需要用我的例子来支持
该页面为我要单击的1个元素生成两个XPath,它们略有不同,因此:
"//*[@id='react-root']/section/main/article/header/div[2]/ul/li[2]/a/span"
"//*[@id='react-root']/section/main/article/header/div[2]/ul/li[2]/span/span"
<a class="_s53mj" href="/these.charming.dogs/followers/"><!-- react-text: 24 --><!-- /react-text --><span class="_bkw5z" title="3,071">3,071</span><!-- react-text: 26 --> followers<!-- /react-text --></a>
我想获得Instagram个人资料的粉丝数量,例如:https://www.instagram.com/these.charming.dogs/
后来我用观察者的数量变化,看看它是否大于1000
我应该怎么做才能让脚本点击这个项目?我注意到xpath只在倒数第二个字段中有所不同
# 1 楼答案
一些替代方案:
css:
header ul>li span[title]
css:
header span[title]
css:
header li+li span[title]
css:
header span span[title], header a span[title]
xpath:
//header//ul/li//span[@title]
xpath:
//header//ul/li[2]//span[@title]
xpath:
//header//span[@title]