Navigation Script

package com.learn.navigation;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class NavigationDemo {
    public static void main(String[] args) throws InterruptedException, MalformedURLException {
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
     
        //Open http://google.co.in

        driver.navigate().to("http://google.co.in");
        Thread.sleep(2000);
        System.out.println("Current Page URL is: " + driver.getCurrentUrl());
     
        URL fb = new URL("http://facebook.com");
        driver.navigate().to(fb);    //Open http://facebook.com
        Thread.sleep(2000);
        System.out.println("Current Page URL is: " + driver.getCurrentUrl());
     
        //Go Back to previous url in the history
        driver.navigate().back();
        System.out.println("Current Page URL is: " + driver.getCurrentUrl());
     
        //Go to next url that is present in the history
        driver.navigate().forward();
        System.out.println("Current Page URL is: " + driver.getCurrentUrl());     
        Thread.sleep(5000);


        //Refresh the current Page
        driver.navigate().refresh();     
        Thread.sleep(3000);

        //Close the browser
        driver.close();
    }
}

No comments:

Post a Comment