Handle Text box, Radio button, Check box, Double Click 

Let’s learn to automate all the elements which are possibly available in any websites.  For this, we will use our site https://demoapp1.tequality.tech/ for practising. Navigate to the Forms page to see all the Web Elements.

To Navigate to Forms page we have to use Click command available in webdriver. Here below is the code to navigate to Forms page. 

public class Forms{

public static void main(String[] args) {

// System Property for Chrome Driver
System.setProperty("webdriver.chrome.driver", "E:\chromedriver.exe");

// Instantiate a ChromeDriver class.
WebDriver driver=new ChromeDriver();

//Maximize the browser window driver.manage().window().maximize();

// Launch Website and navigate to URL

//Click on Forms link

1. Handle Textbox using Webdriver commands

Selenium provides a method called sendKeys() for typing in textbox. This method is been used for simulating typing into an element by setting the value.

Handle Textbox using webdriver commands Example

We will be automating this text field through different ways:




Practice yourself: You can try automating “Text Input with Placeholder” and “Text area field by yourself.


2. Handle Radio Button using Webdriver commands

Only one option can be selected through radio button, so this can toggle using Click() method available in webdriver.

Handle Radio button using webdriver commands Example

Radio button can be automated as below


Practice yourself: You can try automating “Inline Radio Buttons field by yourself.


3. Handle Check box using Webdriver commands

Multiple options can be selected in a checkbox. This can also toggle using Click() method available in webdriver.

Handle checkbox using webdriver commands Example

This checkbox can be automated as below

driver.findElement(By.xpath("//label[text(), 'Checkbox 1']")).click();

Practice yourself: You can try automating “Inline checkboxes field by yourself.


4. Handle Double Click using Webdriver commands

Double click action can be simulated through Action class available in Webdriver. At first Action class object need to be instantiated by passing driver as a parameter, then we pass the webelement need to be double clicked in the double click method available in action class.

Handle double click using webdriver commands Example

Actions action = new Actions(driver);
WebElement element = driver.findElement(By.id("dcbutton"));