Load a New Web Page in Current Browser Window

To load a new web page in current browser window programmatically using Selenium in Java, call WebDriver.get() method and pass the URL string as argument.

WebDriver.get(String url) method loads a new web page in the current browser window using an HTTP POST operation, and the method will block until the load is complete.

The following is a simple code snippet to initialize a web driver and load the URL.

WebDriver driver = new ChromeDriver();
driver.get("https://www.tutorialkart.com/");
ADVERTISEMENT

Example

In the following program, we write Java code to initialize a web driver, and load the URL https://www.tutorialkart.com/ in the browser window.

Java Program

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyAppTest {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");  
    	WebDriver driver = new ChromeDriver();
        driver.get("https://www.tutorialkart.com/");
        driver.quit();
    }
}

Output

Load a New Web Page in Current Browser Window - Selenium