当我在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
这种冲突行为的原因是什么?
答案 0 :(得分:1)
您的XPath中有两个问题。 text()
需要写成小写,而'db3a1a10.png'
(可能只是示例代码中的错误)不得包含勾号。