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 get page html
Advertisements
Javac -source KeyTest.java
Selenium webdriver - Getting Xpath for element in IE
Selenium webdriver - Getting Xpath for element in IE
View source code of a html page using java ..
Javah
Java2
how to get harddisk info using S.M.A.R.T using java
how to get HTTP GET request value using javascript
How to Using timezone_location_get() PHP
How to get the output of JSP program using Bean
How To get DgroupId while using maven.
How to get the output of jsp program using Bean
how to send spaces using get method.
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 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 list to map with out using a loop?
How to get day from date in Java using Calendar?
How to get unique list in Hibernate using Criteria Query?
How to get the data from the database using Servlet or JSP program
How to get the full path location using <input type=file>
How to get xml file form http port using web service
how to get data using dropdownlist, textbox and search button in jsp
How to get data from Oracle database using JSP
Javah -  Header File Generator
How to get the browsed file path into controller bean using JSF icefaces
How to design https connection page using JSP
please let me get code how to insert a data to mysql using setter and getter method by using java

Ads