Selenium User Handbook

Are you looking for a quick reference to turn to every time you need to look up the basic operations of selenium? Well if you are then this is just what you need.
We at Intellipaat understand that it could be a bit of a hassle to remember every aspect of technology and that is why we have come up with a Selenium cheat sheet to assist our learners whenever they need a handy reference containing all the basics of selenium.

We assume that you have a basic understanding of selenium if you are referring to this cheat sheet.
Download the printable PDF of Selenium cheat sheet

Selenium Cheat Sheet

What is selenium?

Selenium is an open-source framework to automate and perform software testing such as smoke tests, integration tests, etc. on web applications. It provides a playback/recording tool and domain-specific language.

Get started with Selenium:

  • Driver Initialization Basics:

    • Firefox WebDriver driver = new FirefoxDriver();
    • Chrome WebDriver driver = new ChromeDriver();                 
    • Internet Explorer WebDriver driver = new SafariDriver();
    • Safari Driver WebDriver driver = new InternetExplorerDriver();
  • Driver Initialization Advanced:

A. Load firefox from different location:

FirefoxProfilefp= new FirefoxProfile();

B. Load firfox addons

File file=new File(“path/to/extension.xpi”);

Selenium Locators:

Selenium locators are used to find and match the webpage elements that selenium interacts with. Following are some locators in selenium:

  • Locating by ID
driver.findElement("q")).sendKeys("Se lenium 3");
  • Locating by Name
driver.findElement("q")).sendKeys ("Selenium 3");
  • Locating by Xpath
driver.findElement(By.xpath("//input[@id='q'])).sendKeys("Selenium 3");
  • Locating Hyperlinksby Link Text
driver.FindElement(By.LinkText("edit this page")).Click();
  • Locating by DOM
dom =document.getElementById('signinForm')
  • Locating by CSS
driver.FindElement(By.CssSelector("#rightbar> .menu >li:nth-of-type(2) > h4"));
  • Locating by ClassName
  • Locating by TagName
driver.findElement(By.tagName("select")).C lick();
  • Locating by LinkText
driver.findElement(By.linkText("NextP age")).click();
  • Locating by PartialLinkText
driver.findElement(By.partialLinkText(" NextP")).click();

Get 50% Hike!

Master Most in Demand Skills Now !

Selenium Navigators:

The navigator interface in selenium helps in moving backwards and forwards in the browser’s history. Following are some navigator commands you can use:

  • Navigate to url
  • Refresh page
  • Navigate forwards in browser history
  • Navigate backwards in browser history


TestNG is an open source framework for automated testing. The NG in TestNG stands for Next Generation. It is similar to Junit but with more functionality to offer. Following are the TestNG annotations:

  • @test: This annotation marks a class or method as a part of a test
  • @BeforeSuite: This annotation makes sure that the method only run once before all the tests have run
  • @AfterSuite: This annotation makes sure that the method runs once after the execution of all the tests
  • @BeforeTest: This annotation will make sure that the method marked with this annotation runs before the first method annotated with @test
  • @AfterTest: This annotation will make sure that the method marked with this annotation runs after all the methods annotated with @test execute all the classes inside <test> tag in the testng.xml file.
  • @BeforeGroups : A method annotated with this annotation will run before all the first test methods run in that specific group
  • @AfterGroups: A method annotated with this annotation will run after all the test methods run in that specific group
  • @BeforeClass: A method annotated with this annotation will run only once per class and before all the first test methods run
  • @AfterClass: A method annotated with this annotation will run only once per class and after all the test methods run
  • @BeforeMethod: A method annotated with this annotation will run before every @test annotated method
  • @AfterMethod: A method annotated with this annotation will run after every @test annotated method


JUNIT is a framework used to perform unit level testing. Following are the JUNIT annotations:

  • @Test: test method to run with public void return type
  • @After: method to run after test method
  • @AfterClass: method to run before test method
  • @Before: method to run before test method
  • @BeforeClass: method to run once before any of the test methods in the class have been executed
  • @Ignore: This annotation is used to ignore a method

Career Transition


sometimes the web applications may have multiple frames or windows. Selenium assigns each window a unique alphanumeric id which is called window handle. Selenuim then uses the id to switch control among windows.

String handle=driver.getWindowHandle();
Set<String> handles = getWindowHandles();
  • How to switch to newly created window

 String curWindow=driver.getWindowHandle();
  • Get all window handles
Set<String> handles = getWindowHandles();
For(string handle: handles){
If (!handle.equals(curWindow))


  • Using Frame Index:
  • Using Name of Frame:
  • Using web Element Object:
  • Get back to main document:


In selenium there are certain operations that can be performed on the web elements. Following is the list of those operations along with their respective syntax:

  • Launch Webpage:
  • Click Button: 
  • Handle Alert:
AlertAlertpopup = driver.switchTo().alert();
  • Disable a Field:
getElementsByName('') [0].setAttribute('disabled', '')
  • Enable a Field :
getElementsByName('') [0].removeAttribute('disabled');
  • Screenshot : 
File snapshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(snapshot, new File("C:\\screenshot.jpg"));
  • Print the Title of the Page:
String pagetitle = driver.getTitle();
  • Implicit Wait: 
manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  • Explicit Wait:
WebDriverWait wait = new WebDriverWait(driver, 20);
  • Sleep :

Watch this Selenium Projects For Beginners Tutorial

Selenium Cheat Sheet


Sometimes a message box pops up on the screen to display some kind of notification to the user or maybe an ask for a permission or to display a warning etc. These messages are called alerts. Alert interface provides some ways to handle the alerts in selenium:

Capture the alert message:


Click on the ‘OK’ button of the alert:


Click on the ‘Cancel’ button of the alert:


Send some data to alert box:


Selenium Grid:

Selenium Grid helps selenium run multiple tests across different operating systems, browsers and machines in parallel.

  • Start hub:
java-jar selenium-server- standalone-x.xx.x.jar-role hub
  • Start node:
java-jar selenium-server- standalone-x.xx.x.jar-role node-hub
  • Server:

Become a Test Architect

Download a Printable PDF of this Cheat Sheet

This would be all for the Selenium cheat sheet. In case you are looking to learn Selenium in-depth then you should definitely check out the Selenium training provided by Intellipaat. In this online training, you will get to learn the automation testing framework for web applications, TDD, selenium architecture, JaCoCo, TestNG, Sikuli. You will work on real-life projects and assignments and prepare yourself for Certified Selenium Professional certification in this Selenium training. On top of that, you will have 24*7 technical support from our experts here at Intellipaat.

Course Schedule

Name Date
Testing Courses 2021-11-27 2021-11-28
(Sat-Sun) Weekend batch
View Details
Testing Courses 2021-12-04 2021-12-05
(Sat-Sun) Weekend batch
View Details
Testing Courses 2021-12-11 2021-12-12
(Sat-Sun) Weekend batch
View Details

Leave a Reply

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