Selenium Tutorials

If you are a beginner, please Proceed here to start from the beginning.

Introduction to Page Object Model Framework

Page Object Model Framework has now a days become very popular test automation framework in the industry and many companies are using it because of its easy test maintenance and reduces the duplication of code.

The main advantage of Page Object Model is that if the UI changes for any page, it don’t require us to change any tests, we just need to change only the code within the page objects (Only at one place). Many other tools which are using selenium, are following the page object model.

Perform operations on new window

There are cases where we need to open new window and perform operations or there may be cases where after clicking on any button / link, it opens new window and need to perform operations on the new window.

Let us look into such example:

Test case: We need to open '' and click on 'Help Center' link at the bottom which will open new window.
1. Verify the title of the new window
2. Verify text 'Welcome' on the page.
3. Search for a Question with text "Frequently Asked Questions" and verify the result.

Working with Select examples

As we have seen earlier WebDriver’s support classes called “Select”, which provides useful methods for interacting with select options. User can perform operations on a select dropdown and also de-select operation using select methods.

We will now show you how to work with select methods using examples tests. We have created a common resuables which can be used across the tests.

Below is the sample test with three test methods. Each with a different example.

Working with Checkbox using Resuable Methods

Working with checkbox is very simple using webdriver. It is same as click operation. But it is always recommended to check if that is already in selected mode or deselected. Because, if it is already selected and when you click on the same element it will get deselected. We will look into different ways to perform select and de-select operations on checkboxes. We will also use reusable methods to perform the operation in multiple tests.

The below is the simple command to do that:

Configure parallel execution of tests using TestNG selenium

In testing, it is always important to test application in different browsers. We can perform automation on multiple browsers using selenium and testng. If there are more number of tests that need to be executed in parallel on different browsers also, we can do this using testng. And there is an other challenging task such executing tests in different browser versions and also different Operating systems. This can be achieved with Selenium Grid.

Examples with xpath and Css (ID, Name, Text and Links)

As we know it is always better to use ID and Name to locate the elements which will work for sure. You don't need to search for any other locator if there is ID or Name present in your application.

Let us look for xpath examples to use ID and Name effectively with combinations

If the html looks like below :

<input type="text" aria-label="Email or Phone" value="Email or Phone" tabindex="1" placeholder="" name="email" id="email" 
class="inputtext _5aju" style="background-color: transparent;">

We can use as below :

Keyword Driven Framework Example

In this framework, keywords are developed which are equal to a unit level functionality. It is an independent framework which perform automation based on the keywords specified in the excel sheet. Based on the type of application, the number of keywords will be increased to handle different functionalities.

The below are the few keywords which are used commonly in the web applications.