Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Selenium xpath包含以开头的文本_Selenium_Xpath - Fatal编程技术网

Selenium xpath包含以开头的文本

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

我需要将此“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:
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 ")]