Selenium APIs for Some Basic Test Automation Actions

If you think about Test Automation, what are the basic actions comes into mind? Clicking on a button, selecting some value from a dropdown, typing in some value into an edit box, clicking on a link, checking a checkbox, clicking on a radio button.

Below are some of the actions we can list:

  1. Click
  2. Select
  3. Type
  4. Check / Uncheck

Let us start exploring APIs provided by Selenium Web Application Test Automation tool for these actions.


To click on any object Selenium provides (“Locator”) API.  Using this we can click on an object on the user interface.


To type some value into an edit box or any control where we can key in values we can utilize the selenium method “selenium.type(“locator”,”value”)”.  For keying in some values into an object we need to first locate the object on the UI and then need to type the value.


For selecting a value from a dropdown, ““locator”,”value”)” API of selenium can be utilized.

In the above selenium methods “locator” can be ID, name, or xpath of an object which is used to identify the object.


There are two methods selenium.check and selenium.uncheck which are used to check / uncheck the Web Checkboxes on the application under test.  Usage is illustrated in the below code snippet.

Let us have a look at the below example code:

package com.selftechy.sqaforums;

 * Author - Seetaram Hegde

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

public class SeleniumAPIs extends SeleneseTestCase {
	private static SeleniumServer seleniumServer;
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*chrome", "");
        seleniumServer = new SeleniumServer();

	public void testOpenTypeClick() throws Exception {"/");"link=Advanced search");
		selenium.type("as_q", "selftechy, selenium");"//input[@value='Advanced Search']");

	public void testSelectCheck() throws Exception {"");"link=Advanced Search");
		selenium.type("bx_jtitle", "Sr. Testing Engineer");"rdjt", "label=All Of These");
		selenium.removeSelection("jids[]", "label=All Categories");
		selenium.addSelection("jids[]", "label=Functional Testing");
		selenium.type("bx_kwd", "selenium");"idrdKeyw1");"id_alltype");
		selenium.check("id_jtp_1");"//input[@name='cmdSearch' and @value='  Search  ']");

	public void tearDown() throws Exception {


The above example illustrates the usage of various Selenium APIs such as, selenium.check, selenium.type,, selenium.addSelection, selenium.removeSelection, selenium.windowMaximize,, etc.  First start automating test cases using Selenium IDE and export the code into your favorite programming language such as Java, C#, PHP, etc.  Then learn using Firebug, Firepath, Xpath Checker, etc to find out the ID, name, or XPath to identify the object.  Map these locators to string variables with meaningful names and use them in the tests.

Comments 4

  • Hi Seetaram,

    In the above example you have mentioned ““locator”,”value”)” for the type category. I reckon it is typo error. My special thanks to you. You are a real genius and I followed your blog and one more blog to learn selenium. Your explanation is so user friendly. Keep up the good work and share us the difficult situations you faced with some application and how you fixed it. It will be helpful for us.

    Thanks ,

  • Hi Seetaram,

    Can you please let me know how you handle secured websites (ex:- websites with “https”) with an example.

    Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.