Lets guess all possible Manual scenario that can be performed on any Browsers –
Launch Browser
Enter the URL
Navigate to another URL
Get the specified URL
Get the Browser Title
Get the page source
Get the browser handle
Close the browser
Navigate back to previous URL
Navigate forward
Refresh the page
Maximize/Minimize the browser
Open the browser in full Screen
Now try to perform above scenarios with Selenium WebDriver Steps:
package HandlingElementsInSelenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.Point;
import org.openqa.selenium.chrome.ChromeDriver;
public class HandlingBrowsers {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
//Create Browser Driver/launch browser with blank url
WebDriver driver = new ChromeDriver();
//Maximize the browser Window
driver.manage().window().maximize();
//Navigate/get to a specified url
driver.get("https://www.facebook.com/");
//Return Browser URL
String browserURL = driver.getCurrentUrl();
System.out.println("Current browser URL is :- "+browserURL);
//Return Browser title
String browserTitle = driver.getTitle();
System.out.println("Browser Title is :- "+browserTitle);
//Return Browser handle (Current window id)
String browserHandle = driver.getWindowHandle();
System.out.println("Current window id is :- "+browserHandle);
//Navigate to other url
driver.navigate().to("https://mail.rediff.com/cgi-bin/login.cgi");
//Navigate back to previous url
driver.navigate().back();
//Navigate forward
driver.navigate().forward();
//Refresh the page
driver.navigate().refresh();
//Browse in full screen
driver.manage().window().fullscreen();
//Return Page source
driver.getPageSource();
//Minimize the browser
Point p = new Point(0,3000);
driver.manage().window().setPosition(p);
Thread.sleep(3000);
//Closer focused browser window
driver.close();
//Close all browser that opened by Selenium WebDriver
driver.quit();
}
}