【问题标题】:Element found in Firebug but not in Selenium在 Firebug 中找到但在 Selenium 中没有的元素
【发布时间】:2016-01-26 15:12:51
【问题描述】:

当我在 Firebug 中检查 XPath 时,它按预期工作。

我正在尝试的 XPath 如下:

.//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.pn`g')][2]

然而,在 Selenium WebDriver 中

 ArrayList<WebElement> al = toolActionObject.getAllElementsByXpath(".//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]");
 System.out.println(al.size());

输出线是这样的

DEBUG (SeleniumActions.java:91) - Locating elements by By.xpath: *//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]
DEBUG (SeleniumActions.java:91) - Locating elements by By.xpath: *//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]
DEBUG (SeleniumActions.java:91) - Locating elements by By.xpath: *//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]
DEBUG (SeleniumActions.java:91) - Locating elements by By.xpath: *//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]
DEBUG (SeleniumActions.java:91) - Locating elements by By.xpath: *//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]
DEBUG (SeleniumActions.java:111) - Exception : Elements not found.
 Cause : Elements not found by By.xpath: *//div[Text()='Data Fields']/following::div[contains(@style,'db3a1a10.png')][2]. Returning empty Array List of WebElement.
0
 INFO (GSUILogInLogOut.java:95) - Clossing browser.
PASSED: testHere

这种冲突行为的原因是什么?

【问题讨论】:

  • 什么是toolActionObject
  • 我正在开发一个框架。在我们的框架中,我们有一个名为 SeleniumActions 的类,我们在其中定义了通过 id、xpath 等访问 Web 元素的方法。toolActionObject 是 SeleniumActions 的实例。
  • 请将相关的 html(从 xpath 开始的位置)添加为文本。
  • following:: 很可能不起作用。检查跨浏览器兼容性。

标签: xpath selenium-webdriver webdriver firebug


【解决方案1】:

您的 XPath 中有两个问题。 text() 需要小写,'db3a1a10.png'(可能只是您的示例代码中的一个错误)不能包含刻度线。

【讨论】:

  • 是的,我在尝试 Text(),它应该是 text()。
猜你喜欢
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 2019-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多