How to get Page Source in Selenium (WebDriver) using Java?

Ads
 

How to get Page Source in Selenium (WebDriver) using Java?

Hi,

I am working on Selenium test cases for testing the web application. Now I have to get the source of the web page.

How to get Page Source in Selenium (WebDriver) using Java?

Thanks

View Answers

October 14, 2016 at 7:48 AM

Hi,

You can use the following code to achieve this:

String pageSource = driver.getPageSource();

Here is the full source code:

package net.roseindia;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class TestLoginApp {

    public static void main(String[] args) {
        WebDriver driver;
        System.setProperty("webdriver.gecko.driver", "C:\\DeepakData\\selenium\\geckodriver.exe");
        driver = new FirefoxDriver();
        driver.get("http://www.roseindia.net");

        String pageSource = driver.getPageSource();
        System.out.println(pageSource);
        driver.close();
        driver.quit();
    }

}

Thanks

Ads









Related Tutorials/Questions & Answers:
How to get Page Source in Selenium (WebDriver) using Java?
Selenium webdriver - Getting Xpath for element in IE
Advertisements
Selenium webdriver - Getting Xpath for element in IE
Javac -source KeyTest.java
Javah
difference between java5 and java6 - Java Beginners
Java2
View source code of a html page using java ..
about java1
how to get HTTP GET request value using javascript
how to get harddisk info using S.M.A.R.T using java
how to get data in jsp page - Framework
How to Using timezone_location_get() PHP
How To get DgroupId while using maven.
How to get the output of JSP program using Bean
How to get the output of jsp program using Bean
how to send spaces using get method.
javaa swings - IDE Questions
Javah -  Header File Generator
How to get month name from date(like-25/06/2012) using java?
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
How can we get second of the current time using date function?
how to get mail exchange records using java dns protocol
how to get popup fro servelt to jsp by using ajax........
How to get data from DB in to Text box by using Jsp & Ajax
How to get day from date in Java using Calendar?
how to get data from list to map with out using a loop?
How to get unique list in Hibernate using Criteria Query?
How to get the full path location using <input type=file>
How to get the data from the database using Servlet or JSP program
How to get xml file form http port using web service

Ads