我正在使用Selenium进行一些工作:脚本应该点击链接,然后点击它自己的地址。例如,有一个方法:clickAndWait。我必须通过它链接标题。但是在我的页面上这个标题发生了变化,所以我必须通过地址点击。
你能帮我解决这个问题吗?
P.S。我在selenium小组问了这个问题,但仍然没有答案。
upd:例如,我有这样的html代码:
<a href="lalala.com">Some changeable title</a>
<a href="another.com">Some changeable title</a>
和selenium pseudocode:
ClickAndWait('Some changeable title')
但我必须点击网站'another.com',而不是'lalala.com'。并且链接的标题每次都会更改。只有链接地址是相同的。
答案 0 :(得分:2)
您可以使用以下定位器之一:
//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