如何为下面的h4节点编写通配符xpath

问题描述 投票:0回答:1

我熟悉

contains()
starts-with()
。我正在寻找一些可以包含“Cucumber”的 XPath reg 表达式,并且后面的任何内容都应与通配符匹配。这可能吗?

<h4 class="product-name">Cucumber - 1 Kg</h4>

我尝试过这个但不起作用:

By.xpath("//h4[contains(text(),'" + Cucumber + "')]
selenium-webdriver xpath wildcard
1个回答
0
投票

您的 XPath 中的单引号和双引号不匹配,并且您没有在代码中关闭双引号或括号。下面的应该可以工作。

By.xpath("//h4[contains(text(),'Cucumber')]")
© www.soinside.com 2019 - 2024. All rights reserved.