Selenium xPath:无效的选择器-为同一元素传递多个条件时

时间:2018-11-28 10:03:26

标签: selenium selenium-webdriver xpath

无效的选择器:无法找到带有XPath表达式的元素:

//span[@class='title-subGrid-lite-TextAutoEllipsis’][text()[contains(.,'My Emails')]

纠正我。

1 个答案:

答案 0 :(得分:2)

此错误消息...

org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //span[@class='title-subGrid-lite-TextAutoEllipsis’][text()[contains(.,'My Emails')]

...表示您使用的 XPath 不是有效的。

您如下使用的 xpath 表达式有两个问题:

//span[@class='title-subGrid-lite-TextAutoEllipsis’][text()[contains(.,'My Emails')]
  • class 属性需要正确放置在单引号之间,即'...'
  • text 属性需要正确放置在[...]之间

必须满足您的要求的简单 XPath 表达式是:

//span[@class='title-subGrid-lite-TextAutoEllipsis'][contains(.,'My Emails')]

您也可以尝试:

//span[@class='title-subGrid-lite-TextAutoEllipsis' and contains(.,'My Emails')]

也许您必须在寻找:

//span[@class='title-subGrid-lite-TextAutoEllipsis'][normalize-space()='My Emails']