Thursday 13 June 2013

Working with the different types of web elements

In this post we will see how to work with different webelemts.

By default , selenium defines predefined functions which we can use on different types of webelemts.
Here are some of the predefinied functions:

                driver.findElement(By.id("WebelemntId")).clear();
driver.findElement(By.id("WebelemntId")).isEnabled();
driver.findElement(By.id("WebelemntId")).isDisplayed();
driver.findElement(By.id("WebelemntId")).submit();
driver.findElement(By.id("WebelemntId")).sendKeys("test");
driver.findElement(By.id("WebelemntId")).isSelected();
driver.findElement(By.id("WebelemntId")).getAttribute("");
driver.findElement(By.id("WebelemntId")).getLocation();
driver.findElement(By.id("WebelemntId")).getTagName();
driver.findElement(By.id("WebelemntId")).getText();
driver.findElement(By.id("WebelemntId")).getSize();

All the functions canot be used for every webelement.

Say  "sendKeys()" method is sending text to a webelement .This method can be used with textboxes but we can't use it on images , links. These are all basic things which we will learn through experience.

Here are the samples , on how to achieve basic functionality of different webelements using webdriver functions:

Textboxes :Send text
Sending text to Textboxes can be done by using "sendKeys()" method. Here is how it works:
  1. driver.findElement(By.id("textBoxId")).sendKeys("sending text");  
RadioButtons :Select an option
Selecting an option from Radio button can be done by using "click()" method.Here is how it works:
  1. driver.findElement(By.id("radioButtonId")).click();  
Hyperlinks :Click on links
Clicking on link can be done by using "click()" method.Here is how it works:
  1. driver.findElement(By.id("linkId")).click();  
Checkboxes :Check the checkboxes
Selecting options from Checkboxes can be done by using "click()" method.Here is how it works:
  1. driver.findElement(By.id("checkBoxId")).click();  
Drop-down List :Select an option
Selecting an option from Dropdown list  can be done by using  "sendKeys()" method.Here is how it works:
  1. driver.findElement(By.id("dropdownListId")).sendKeys("SelectOption1");  
Textarea :Send text
Sending text to Textboxes can be done by using "sendKeys()" method.Here is how it works:
  1. driver.findElement(By.id("textAreaId")).click();  
Button :click on it.
Submitting button can be done by using either "click()" or "submit()" mrthods.Here is how it works:
  1. driver.findElement(By.id("butonId")).click();  

No comments:

Post a Comment