Selenium Web Objects scripts
Below script to identify the Web objects - Text box, radio button, checkbox, list box, drop down box, Table, Links and Submit buttons.
d5//SCRIPT NAME : Object identifications script - use the webobjects.html application
//This script will give the complete insight of objects identifications, Table, Iframes and alserts.
package Package;
//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class AzziAutomation
{
public static void main (String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");
String url ="http://www.xpr2t.com/Webobjects.html";
// Maximize the browser
driver.manage().window().maximize();
// Open the application in the browser
driver.get(url);
// driver.navigate().to(url); ---- ANOTHER WAY OF PASSING URL
// Hard wait for 5 sec
// Thread.sleep(5000);
// TEXT FIELD IDENTIFICATION
driver.findElement(By.id("usernameid")).sendKeys("Selenium");
// get title
String title=driver.getTitle();
System.out.println(title);
// ************* ANOTHER WAY OF TEXT FIELD IDENTIFICATION *********************************
// WebElement username= driver.findElement(By.id("usernameid"));
// username.sendKeys("selenium");
// *****************************************************************************************
//SLEEP
Thread.sleep(5000);
//GET TEXT FROM TEXTFIELD - 2 WAYS CAN RETRIVE TEXT FROM TEXT FILED
String text=driver.findElement(By.id("usernameid")).getText();
// String text=driver.findElement(By.id("usernameid")).getAttribute("value");
//PRINT THE VALUE IN THE CONSOLE
System.out.println("text filed value is :" +text);
// CLEAR TEXTFILED
driver.findElement(By.id("usernameid")).clear();
String retrun =driver.findElement(By.id("usernameid")).getAttribute("value");//test
System.out.println("get attribute method:" +retrun);
boolean returnvalue= driver.findElement(By.id("usernameid")).isEnabled();
System.out.println("is enabled method :" +returnvalue);
boolean returnvalue1= driver.findElement(By.id("usernameid")).isDisplayed();
System.out.println("is displayed method :" +returnvalue1);
//RADIO BUTTON IDENTIFICATION
driver.findElement(By.name("radiobutton1")).click();
driver.findElement(By.name("radiobutton2")).click();
driver.findElement(By.name("radiobutton3")).click();
//CHECKBOX IDENTIFICATION
driver.findElement(By.name("checkthebox")).click();
// SELECT DROP DOWN BOX
Select drp = new Select(driver.findElement(By.id("test")));
drp.selectByVisibleText("Blue");
// SELECT MULTIPLE VALUES FROM LIST BOX
Select mullist = new Select(driver.findElement(By.name("dropdown")));
mullist.selectByVisibleText("Audi");
mullist.selectByVisibleText("Honda CRV");
//CLICK ON LINK
driver.findElement(By.linkText("1.Yahoo")).click();
Thread.sleep(2000);
//NAVIGATE BROSER BACK
driver.navigate().back();
Thread.sleep(5000);
// Relative XPATH for Submit button
// driver.findElement(By.xpath(".//input[@type='submit']")).click();
// absloute path - html/body/font/p[1]/input
driver1.findElement(By.xpath("html/body/table[6]/tbody/tr[2]/td[2]/input")).click();
//CLOSE THE CURRENT BROWSER
driver.close();
//CLOSE ALL OPENED BROWSERS
driver.quit();
}
}
Below script to identify the Web objects - Text box, radio button, checkbox, list box, drop down box, Table, Links and Submit buttons.
d5//SCRIPT NAME : Object identifications script - use the webobjects.html application
//This script will give the complete insight of objects identifications, Table, Iframes and alserts.
package Package;
//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class AzziAutomation
{
public static void main (String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");
String url ="http://www.xpr2t.com/Webobjects.html";
// Maximize the browser
driver.manage().window().maximize();
// Open the application in the browser
driver.get(url);
// driver.navigate().to(url); ---- ANOTHER WAY OF PASSING URL
// Hard wait for 5 sec
// Thread.sleep(5000);
// TEXT FIELD IDENTIFICATION
driver.findElement(By.id("usernameid")).sendKeys("Selenium");
// get title
String title=driver.getTitle();
System.out.println(title);
// ************* ANOTHER WAY OF TEXT FIELD IDENTIFICATION *********************************
// WebElement username= driver.findElement(By.id("usernameid"));
// username.sendKeys("selenium");
// *****************************************************************************************
//SLEEP
Thread.sleep(5000);
//GET TEXT FROM TEXTFIELD - 2 WAYS CAN RETRIVE TEXT FROM TEXT FILED
String text=driver.findElement(By.id("usernameid")).getText();
// String text=driver.findElement(By.id("usernameid")).getAttribute("value");
//PRINT THE VALUE IN THE CONSOLE
System.out.println("text filed value is :" +text);
// CLEAR TEXTFILED
driver.findElement(By.id("usernameid")).clear();
String retrun =driver.findElement(By.id("usernameid")).getAttribute("value");//test
System.out.println("get attribute method:" +retrun);
boolean returnvalue= driver.findElement(By.id("usernameid")).isEnabled();
System.out.println("is enabled method :" +returnvalue);
boolean returnvalue1= driver.findElement(By.id("usernameid")).isDisplayed();
System.out.println("is displayed method :" +returnvalue1);
//RADIO BUTTON IDENTIFICATION
driver.findElement(By.name("radiobutton1")).click();
driver.findElement(By.name("radiobutton2")).click();
driver.findElement(By.name("radiobutton3")).click();
//CHECKBOX IDENTIFICATION
driver.findElement(By.name("checkthebox")).click();
// SELECT DROP DOWN BOX
Select drp = new Select(driver.findElement(By.id("test")));
drp.selectByVisibleText("Blue");
// SELECT MULTIPLE VALUES FROM LIST BOX
Select mullist = new Select(driver.findElement(By.name("dropdown")));
mullist.selectByVisibleText("Audi");
mullist.selectByVisibleText("Honda CRV");
//CLICK ON LINK
driver.findElement(By.linkText("1.Yahoo")).click();
Thread.sleep(2000);
//NAVIGATE BROSER BACK
driver.navigate().back();
Thread.sleep(5000);
// Relative XPATH for Submit button
// driver.findElement(By.xpath(".//input[@type='submit']")).click();
// absloute path - html/body/font/p[1]/input
driver1.findElement(By.xpath("html/body/table[6]/tbody/tr[2]/td[2]/input")).click();
//CLOSE THE CURRENT BROWSER
driver.close();
//CLOSE ALL OPENED BROWSERS
driver.quit();
}
}
No comments:
Post a Comment