page.getByXPath("//*[@href='http://www.example.com/index.do/abc/1_*'");
我需要转义任何字符吗?
我正在尝试获取页面上所有具有以下模式的 ahref 链接:
http://www.example.com/index.do/abc/1_
所以这些都应该被检索:
http://www.example.com/index.do/abc/1_asdf-asdfasdf
http://www.example.com/index.do/abc/1_223
http://www.example.com/index.do/abc/1_as.php
http://www.example.com/index.do/abc/1_2222233
最佳答案
XPath 中没有通配符。你想要这样的东西:
page.getByXPath("//*[contains(@href,'http://www.example.com/index.do/abc/1_')]");
这依赖于the contains
function .您还可以使用 starts-with
函数:
//*[starts-with(@href,'http://www.example.com/index.do/abc/1_')]
关于java - 这个 xpath 看起来正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2008709/