html - 通过地址模板点击链接

标签 html dom selenium click

我正在使用 Selenium为了做一些工作:脚本应该点击链接,然后点击它自己的地址。比如有一个方法:clickAndWait。我必须传递它链接标题。但是在我的页面上这个标题改变了,所以我必须传递地址才能点击。

你能帮我解决这个问题吗?

附注我在selenium群里问过这个问题,还是没有答案。


upd: 例如,我有这样的 html 代码:

<a href="lalala.com">Some changeable title</a>
<a href="another.com">Some changeable title</a>

和 Selenium 伪代码:

ClickAndWait('Some changeable title')

但我必须点击网站“another.com”,而不是“lalala.com”。并且链接的标题每次都会更改。只有链接地址相同。

最佳答案

您可以使用以下定位器之一:

//use XPath to match links with full href value
selenium.clickAndWait("//a[@href='another.com']");

//use XPath to match links with href values that start with string
selenium.clickAndWait("//a[starts-with(@href,'another.com')]"); //use partial href value

//use XPath to match links with href values that contain string
selenium.clickAndWait("//a[contains(@href,'another.com')]"); //use partial href value

关于html - 通过地址模板点击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2864855/

相关文章:

javascript - HTML/css/Javascript云幻灯片

javascript - CSS不透明度动画改变位置?

java - org.openqa.selenium.SessionNotCreatedException : session not created exception from tab crashed error when executing from Jenkins CI server

javascript - 如何使用 HTML/javascript 以预定义的顺序加载图像?

html - 为什么无论内容大小如何,我的 CSS(显然)都会强制显示滚动条?

javascript - onkeydown 事件变量打破 EventListener 代码

javascript - 在 React 中访问子元素的 DOM 节点

python - 如何使用 Selenium 和 Python 2.7 单击表单中的按钮?

javascript - 用正确的例子解释 "SLIDER"在 Protractor 上的拖放

jquery - 如何访问css效果,在类的jquery函数调用中