Sample selenium test scripts for navigating an application
In this tutorial, I explain how to write webdriver test script for navigating an application.
Let us try to create a WebDriver script that would:
- Open Google application
- Clicks on "Sign in"
- Navigating (Back & Forward)
- Refresh
WebDriver Script:
package com.selenium.practise;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class GoogleNavigation {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:\\Soft Wares\\chromedriver.exe");
// Set path created for ChromeDriver
WebDriver driver = new ChromeDriver();
// -> Here we are using ChromeDriver.
// -> ChromeDriver() object created and assigned object to WebDriver interface
WebDriver.Navigation move = driver.navigate();
// navigate() allows the driver navigate to URL and access the browser's history
// WebDriver.Navigation is interface
move.to("http:\\www.google.com");
// Get Google application
driver.findElement(By.id("gb_70")).click();
// clicking on Sign in
move.forward();
// moves forward to Sign in page
move.back();
// moves back to Google main page
move.refresh();
// refresh current page
driver.close();
// close application
System.out.println("Navigation is success");
}
}