Selenium xpath包含以开头的文本
我需要将此“foo”元素与selenium匹配:Selenium xpath包含以开头的文本,selenium,xpath,Selenium,Xpath,我需要将此“foo”元素与selenium匹配: <div class="d95 abc 123">foo</div> 但这给了我: InvalidSelectorError: Unable to locate an element with the xpath expression //div[text()[contains(.,"foo")] starts-with(@class, "d95 ")] because of the following error: S
<div class="d95 abc 123">foo</div>
但这给了我:
InvalidSelectorError: Unable to locate an element with the xpath expression //div[text()[contains(.,"foo")] starts-with(@class, "d95 ")] because of the following error:
SyntaxError: The expression is not a legal expression.
我一直在寻找这段代码,但我看不出有什么问题。如果有人能给我一个提示,这对我会有很大帮助
非常感谢本例中的要点和text()
是相同的。这两个条件都适用于div
。因此,我们可以将它们与和
//div[contains(.,"foo") and starts-with(@class, "d95 ")]
这样行吗
//div[text()='foo'][starts-with(@class, "d95 ")]
这不匹配,如果我单独做的话,首先将我的div与文本foo匹配,然后检查它是否有正确的类,我就得到了我想要的元素
//div[text()='foo'][starts-with(@class, "d95 ")]