package selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.ChromeDriver;
public class Browsercommands {
@SuppressWarnings("deprecation")
public
static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");
//Initialize WebDriver
WebDriver driver = new ChromeDriver();
// Wait For the Page To Load
driver.manage().timeouts().implicitlyWait(60,
TimeUnit.SECONDS);
// Go to URL
driver.get("https://suriyaparithy.blogspot.com/");
// Maximize Window
driver.manage().window().maximize();
// Storing Title name in String variable so
that we can get the title name
String title = driver.getTitle();
// Printing the Title name in 2 ways
// 1st way
System.out.println(title);
// 2nd way
System.out.println("Title is : " +
title);
// Storing Title length in Int variable
because we are dealing with Integers that's why int is used.
int TitleLength = driver.getTitle().length();
// Printing Title length
System.out.println("Length of the Title
is : " + TitleLength);
// Storing URL in String variable
String curl = driver.getCurrentUrl();
// Printing URL on Console Window
System.out.println("URL is :
" + curl);
// Storing URL length
int curl2 = driver.getCurrentUrl().length();
// Printing URL length on console Window
System.out.println("URL length is
: " + curl2);
// COMMAND FOR NAVIGATION THROUGH
PAGES.
//Open the TCA Page
String tca =
driver.findElement(By.linkText("TCA")).getText();
// Print the Tab name which is being
clicked.
System. out.println("Name
of the Tab which is being clicked is: " + tca);
// Click on the TCA Tab
driver.findElement(By.linkText("TCA")).click();
//Navigate to the previous Page.
driver.navigate().back();
Thread.sleep(1000);
String pre =
driver.getTitle();
// Print the text of the
previous page
System.out.println("Text of the previous page is : " + pre);
//Navigate to the Next
page.
driver.navigate().forward();
Thread.sleep(1000);
// Print the text of the NEXT
page
String next
= driver.getTitle();
System.out.println("Text of the
NEXT page is : " + next);
// COMMAND FOR REFRESHING
THE CURRENT PAGE
driver.navigate().refresh();
// PAGE SOURCE COMMAND
/* Storing Page
Source in String variable.
String source = driver.getPageSource();
Thread.sleep(1000);
// Printing
the Page Source
System.out.println("Page source : " + source);
// Storing
Page Source length in Int variable
int
sou = driver.getPageSource().length();
// Printing
the Page Source length
System.out.println("Length of the page source is : " + sou);*/
//close
the browser or page currently which is having the focus.
driver.close();
//Close all the windows.
driver.quit();
}
}