//Command to invoke firefox browser
WebDriver driver=null;
driver = new FirefoxDriver();

//Command to open URL
driver.get("http://testautomationbydurgaprasad.blogspot.in/");

//Command to Click on particular WebElement
driver.findElement(By.xpath("//a[text()='XPath Locators']")).click();
//Command to Clear some text in Text Box
driver.findElement(By.id("idUserName")).clear();

//Command to Enter/Type some text in Text Box
driver.findElement(By.id("idUserName")).sendKeys("Durga");

//Command to Get and Store Text value from targeted WebElement in Variable
String fetchedValue=driver.findElement(By.xpath("//label[1]")).getText();
System.out.println("Fetched Value is..."+fetchedValue);

//Command to Get browser Window Title
String window_Title=driver.getTitle();
System.out.println("Window Title is....."+window_Title);

//Command to get Current URL from browser address bar
String currentURL=driver.getCurrentUrl();
System.out.println("Current URL is....."+currentURL);

//Command to get the HTML Page Source
String htmlPageSource=driver.getPageSource();
System.out.println("HTML Page Source is..."+htmlPageSource);

//Command to Navigate Forward
driver.navigate().forward();

//Command to Navigate to Back
driver.navigate().back();

//Command to Select/DeSelect DropDown Value and possible ways
WebElement ele=driver.findElement(By.xpath("//select[@class='country']"));
Select select = new Select(ele);
//TYPE 1:
//Select By VisibleText Value
select.selectByVisibleText("India");
//DeSelect By VisibleText Value
select.deselectByVisibleText("India");
//TYPE 2:
//Select by Value
select.selectByValue("India");
//DeSelect By Value
select.deselectByValue("India");
//TYPE 3:
//Select by Index value
select.selectByIndex(0);
//DeSelect by Index value
select.deselectByIndex(0);

Categories: