Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java seleniumwebdriver和regex_Java_Regex_Xpath_Selenium Webdriver - Fatal编程技术网

Java seleniumwebdriver和regex

Java seleniumwebdriver和regex,java,regex,xpath,selenium-webdriver,Java,Regex,Xpath,Selenium Webdriver,我使用Selenium 2.35.0、最新的Firefox和Linux操作系统 我无法在java应用程序中使用正则表达式 我有这样一句话: Iterator<WebElement> iterator = driver.findElements(By.xpath("//a[matches(@href, 'site.ru/[0-9]*/')]")).iterator(); 迭代器迭代器= driver.findelelements(By.xpath(“//a[matches(@href

我使用Selenium 2.35.0、最新的Firefox和Linux操作系统

我无法在java应用程序中使用正则表达式

我有这样一句话:

Iterator<WebElement> iterator =
driver.findElements(By.xpath("//a[matches(@href, 'site.ru/[0-9]*/')]")).iterator();
迭代器迭代器=
driver.findelelements(By.xpath(“//a[matches(@href,'site.ru/[0-9]*/'))]”);
发生异常:

org.openqa.selenium.InvalidSelectorException:给定的选择器 //[匹配项(@href,“site.ru/[0-9]/”)无效或无效 生成一个WebElement。发生以下错误: InvalidSelectorError:无法找到具有xpath的元素 表达式//a[匹配项(@href,“site.ru/[0-9]/”)


你能帮我调查一下这个故障的原因吗?

最好看看你的真实输入,或者其中一部分显示了问题,但也许这会有所帮助

//a[matches(@href, 'site.ru/[0-9]*/')]
针对这些链接:

<html>
  <div>
    <a href="site.ru//">Link 1</a>
    <a href="site.ru/123/">Link 2</a>
    <a href="http://site.ru/123/">Link 3</a>
    <a href="site.ru/">Link 4</a>
    <a href="site.ru/123">Link 5</a>
    <a href="site.ru/abc/123">Link 6</a>
  </div>
</html>

如果这太自由了,并且选择了您不想匹配的案例,那么请在下面评论哪些特定案例必须排除,我们将尝试进行相应的调整。

也许您需要像这样匹配所有href文本。*site.ru/[0-9]*/.@Darka,不错,但是XPath
匹配()如果ReGEX存在于字符串中的任意位置,则函数已经匹配。我只想匹配链接1-3,但它不起作用(参见初始问题描述中的异常)。考虑到XPath是正确的,考虑到输入可能不包含我们所认为的。建议您发布实际输入。第二个选择是扩展XPath,看看是否可以选择任何非限定的
a
作为健全性检查。
//a[matches(@href, 'site.ru/[0-9]*')]