2

I am using Selenium and Java to write a test, when I use the code below:

List<WebElement> elements = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy
    (By.xpath("//div[.//span[text()='Map']]//*")));

for (WebElement e : elements) {
    System.out.println("=>" + e.getTagName() + "<=");                   
}

it shows all the web elements in that <div> tag.

Result:

=>span<=
=>div<=
=>div<=
=>path<=
=>path<=
=>span<=

As you see, some of the elements tag-name is path but when I use the code below it says that I could not find the element.

List<WebElement> elements = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy
    (By.xpath("//div[.//span[text()='Map']]//path")));
Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
LoveJavaTwo
  • 215
  • 3
  • 17

3 Answers3

0

It not easy to find the real issue with out knowing your HTML structure.

While I think there is a issue in your xpath

Try below xpath

//div//span[text()='Map']//path

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

By.xpath("//div[.//span[text()='Map']]//* will return all the decedents of span[text()='Map'] in the html hierarchy.

For example, this html structure will produce the same results you have

<div>
  <span>Map</span>
  <div></div>
  <div>
    <path></path>
    <path></path>
  </div>
  <span></span>
</div>

As you can see, <path> is not <span> direct child, so By.xpath("//div[.//span[text()='Map']]//path is not a valid xpath.

Guy
  • 46,488
  • 10
  • 44
  • 88
  • @LoveJavaTwo I changed the html little bit, now it works. I tested it on (probably) another site so I didn't have the exact html structure. – Guy Feb 03 '16 at 05:44
0

The issue was related to some web elements that Selenium cannot navigate, the web element that I was trying to catch was inside a svg web element which is not detectable by Selenium have a look here this is exactly what was happening to me.

Community
  • 1
  • 1
LoveJavaTwo
  • 215
  • 3
  • 17