jquery - Selenium:根据兄弟元素文本选择元素

标签 jquery css selenium testing xpath

我一直在为以下目标开发 selenium 脚本: http://live.guru99.com/index.php/mobile.html?dir=asc&order=position

并想为 "Sony Xperia" 选择元素 "Add to Compare" 但它没有定位。 我已经尝试使用 cssSelectorxpath 两者,但无法弄清楚我做错了什么。

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/

相关文章:

Nodejs 中的 jquery ajax 无法使用 https 获取/发布

php - 如果你需要 3 个 'tiers' 的引号,你会怎么做?

javascript - 在页面上显示多个输入字段并通过单选按钮更改字体

css - 用于 Typescript 的 SVG-React 组件

python selenium webdriver safari 驱动程序

python - Selenium.common.exceptions.WebDriverException : Message: unknown error: no chrome binary

jquery - 仅影响父 LI

javascript - $ (":focus") 在 Firefox 中没有为 <input type ="file"/> 返回任何元素

javascript - 如何解析来自github的csv?

python - 将网页抓取的表格放入excel(selenium,python)