0
public class URL {

    WebDriver driver;
    @Test
    public void test_URL() throws InterruptedException{

        driver = new FirefoxDriver();

        //driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.get("https://www.proptiger.com/city-image-sitemap.xml");

        List<WebElement> links = driver.findElements(By.tagName("loc"));
        System.out.println(links.size());

        for(int i=0; i<links.size();i++){
            //Thread.sleep(200);
            System.out.println(i+ "."+links.get(i).getText());
        }
    }
}

Suddenly It is stop execution. It is not given all tag values. I want all links in this page.

kuro
  • 3,214
  • 3
  • 15
  • 31
Jakay
  • 40
  • 7

3 Answers3

0

Selenium does not handle XML. It only handles HTML. There are various plugins for xml parsing that might help you.

There is a solution of your problem on stackoverflow. Please have a look on this - https://stackoverflow.com/a/8445497

Ankur
  • 893
  • 3
  • 12
  • 29
0

You can handle XML by Selenium using a different approach. Try this xpath : //*[name()='loc'] for finding all the tag values

Try this code:

    System.setProperty("webdriver.gecko.driver", "src/geckodriver");
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.get("https://www.proptiger.com/city-image-sitemap.xml");

        List<WebElement> links = driver.findElements(By.xpath("//*[name()='loc']"));
        System.out.println(links.size());

        for(int i=0; i<links.size();i++){
            //Thread.sleep(200);
            System.out.println(i+ "."+links.get(i).getText());
        }
Monika
  • 714
  • 1
  • 4
  • 10
0

Try this code it worked for me perfectly

   driver.get("url");

    List<WebElement> links = driver.findElements(By.xpath("//*[contains(@class,'text') and contains(text(),'https')]"));
    System.out.println(links.size());

    for(int i=0; i<links.size();i++){
        //Thread.sleep(200);
        System.out.println(i+ "."+links.get(i).getText());
    }