2

I am trying to print xpath of all the elements on the page. I am finding all the elements of the page and adding it to a list. Here is what i have tried :

 driver.get("http://www.google.com/");
 List<WebElement> ele = driver.findElements(By.xpath("//*"));
 int size = ele.size();
 System.out.println(size);

  for (WebElement el : ele)
   {
        String text = el.getText();
        System.out.println(text + " --  " + el);
   }

Currently while running the code its printing the complete element like :

 About --  [[ChromeDriver: chrome on XP (88e27720e873e9eedfd7819a8601fea2)] -> xpath: //*]

What i want is to print like this ( relative xpath or partial xpath) :

 About -- //*[@id='fsl']/a[3]

Note : I have tried the answer to "Want to Retrieve Xpath of Given WebElement" on comment. Its returning absolute path. Is there any way to convert absolute path to relative path or get relative/partial path directly?

Sijin
  • 138
  • 9
  • 1
    Possible duplicate of [Want to Retrieve Xpath of Given WebElement](https://stackoverflow.com/questions/47069382/want-to-retrieve-xpath-of-given-webelement) – j.barrio Aug 03 '18 at 06:07
  • Maybe that helps you: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5520 – j.barrio Aug 03 '18 at 06:32
  • @j.barrio : Got confused . I actually want to get relative/partial path. – Sijin Aug 03 '18 at 06:50

0 Answers0