我一直在为以下目标开发 selenium 脚本: http://live.guru99.com/index.php/mobile.html?dir=asc&order=position
并想为 "Sony Xperia"
选择元素 "Add to Compare"
但它没有定位。
我已经尝试使用 cssSelector
和 xpath
两者,但无法弄清楚我做错了什么。
CSS 选择器:
div.category-products > ul > li:nth-child(n):contains('Sony Xperia') > div > div.actions > ul > li:nth-child(2) > a
XPath:
//h2/a[@title='Sony Xperia']/ul/li/a[text()='加入比较']
注意:cssSelector
位于 Chrome 中,但在 Firefox 中没有给出任何结果
最佳答案
第二行是你丢失的部分
//h2[a[@title='Sony Xperia']]
/following-sibling::div[@class='actions']
/ul/li/a[text()='Add to Compare']
关于jquery - Selenium:根据兄弟元素文本选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36965368/