Selenium WebDriver action commands and operations

In this section we will see few basic webdriver commands to perform some actions on web element of your web application. Following are the most commonly used commands of selenium webdriver to use in automation process of any software web application.

1) Open URL In Browser
driver.get("https://selenium-vinod.blogspot.in");

2) Clicking on any element or button of webpage
driver.findElement(By.id("submitButton")).click();

3) Store text of targeted element in variable
String dropdown = driver.findElement(By.tagName("select")).getText();

4) Type text in text box or text area.
driver.findElement(By.name("fname")).sendKeys("My First Name");

5) Get page title 
driver.getTitle();

6) Get Current Page URL 
driver.getCurrentUrl();

7) Get domain name using java script executor
JavascriptExecutor javascript = (JavascriptExecutor) driver;
String CurrentURLUsingJS=(String)javascript.executeScript("return document.domain");

8) Generate alert 
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Starting test execution..');");

9) Select value form dropdown by visible text
Select mydrpdwn = new Select(driver.findElement(By.id("Carlist")));
mydrpdwn.selectByVisibleText("Audi");

10) Select value from dropdown by value
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByValue("Italy");

11) Select value from dropdown by index
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByIndex(0);

12) Deselect value from dropdown by Visible Text
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByVisibleText("Russia");

13) Deselect value from dropdown by value
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByValue("Mexico"); 

14) Deselect value from dropdown by index
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByIndex(5);

15) Deselect all values from dropdown
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectAll();

16) To check if select box is multiselect
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
boolean value = listbox.isMultiple();

17) Verify element present 
Boolean iselementpresent = driver.findElements(By.xpath("//input[@id='text2']")).size()!= 0;

18) Element is Enabled Or Disabled
boolean fname = driver.findElement(By.xpath("//input[@name='fname']")).isEnabled();

19) Submit() method to submit form
driver.findElement(By.xpath("//input[@name='Company']")).submit();

20) Reading Font Properties
WebElement text = driver.findElement(By.id("fname"));
String fontColor = text.getCssValue("color");
String fontFamily = text.getCssValue("font-family");
String fonttxtAlign = text.getCssValue("text-align");

21) Get X Y Coordinates Of Element
WebElement Image = driver.findElement(By.id("profilepicture"));
Point point = Image.getLocation();
int xcordinate = point.getX();
int ycordinate = point.getY();

22) Get Height And Width Of Element
WebElement Image = driver.findElement(By.id("profilepicture"));
int ImageWidth = Image.getSize().getWidth();
nt ImageHeight = Image.getSize().getHeight();


23) Wait For Page To Load/Ready
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("return document.readyState").toString().equals("complete");



<-- Previous || Next -->



1 comment:

  1. You are doing a good job and sharing your knowledge to others! it was one of the good post to read and useful to improve the knowledge as updated one, keep doing the good work.

    Selenium Training in Electronic City, Bangalore my knowledge as updated one, keep blogging.

    ReplyDelete