【问题标题】:selenium: Concat xpath function is not working in internet explorerselenium:Concat xpath 函数在 Internet Explorer 中不起作用
【发布时间】:2013-12-20 15:07:38
【问题描述】:

我在 Internet Explorer 10 中执行和执行 xpath 功能时遇到问题。它在 Firefox 甚至 Chrome 上都能完美运行,但在 IE 上却失败了。我需要搜索以下错误信息:

We cannot find this car, please click on "I don't know my car reg" above

这个消息的问题是双引号和不要的引号。

无法使用:

//span[@id='id']//*[text()='We cannot find this car, please click on "I don't know my car reg" above']

//span[@id='id']//*[text()="We cannot find this car, please click on "I don't know my car reg" above"]

所以我尝试了这个:

//span[@id='id']//*[text()=concat('We cannot find this car, please click on "I don',"'",'t know my car reg" above')]'

concat 函数在 chrome 和 fiferox 中完美运行,但在 IE 中出现以下异常:

org.openqa.selenium.InvalidSelectorException: The xpath expression '//span[@id='quoteForm:registrationLookupPart:m1']//*[text()=concat('We cannot find this car, please click on "I don',"'",'t know my car reg" above')]' cannot be evaluated or does notresult in a WebElement (WARNING: The server did not provide any stacktrace information)

有人知道为什么 Selenium IE 驱动会抛出这个异常吗?

它看起来像 concat 函数,或者在 IE 中不存在,或者工作方式不同。这是真的吗?

非常感谢

【问题讨论】:

    标签: internet-explorer selenium xpath concat


    【解决方案1】:

    IE 没有提供本机 xpath 实现,因此 selenium 必须提供自己的实现,这很可能是它失败的情况之一。一般的建议是,如果您不需要,则永远不要使用 xpath,而是使用 css 选择器,因为这工作得更快。我不确定这是否可能,因为您尚未发布 html。

    【讨论】:

    • html 代码如下。在这种情况下可以使用 css 定位器吗?

      我们找不到这辆车,请点击上方的“我不知道我的车牌”

    【解决方案2】:

    几个选项:

    在 XPath 中使用部分文本匹配:

    //*[contains(text(), "We cannot find this car, please click on")]
    

    通过类名查找元素:

    findElement.ByClass("rich-message-label");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-21
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 2015-03-16
      • 2012-05-06
      • 2011-06-02
      相关资源
      最近更新 更多