Selenium Tutorial

Selenium is one of the automation testing tools which is an open source tool. Selenium automates web application. In this Free Selenium training tutorial, we cover all Selenium concepts (basic selenium scripts to advanced testing framework) in detail with easy to understand practical examples. This Selenium Tutorial is helpful for beginners to advanced level users who want to learn selenium or learn automation.

Why This Selenium WebDriver Tutorial?
In this Selenium Web Driver Tutorial, you will learn how to work with the selenium to create automated tests scripts (selenium scripts) for any Web Browser applications and how to create your own framework

Manual Testing Vs Automation Testing in Software Testing

We know that every project has three important aspects such as Quality, Cost & Time. The objective of any project is to get a high-quality output while controlling the cost and the time required for completing the project.

What is Software Testing?

But first, let’s clarify the term ‘Software Testing’.

Software testing is a process, to evaluate the functionality of a software application with an intent to find whether the developed software met the specified requirements or not and to identify the defects to ensure that the product is defect free in order to produce the quality product.

Check this ANSI/IEEE 1059 Standard Definition of Software Testing.

Software Testing is an integral part of any project.

Software testing is categorized into two areas namely Manual Testing & Automation Testing. Both manual testing and automation testing has their own advantages and disadvantages but it’s worth knowing the difference between manual & automation testing and when to you use manual testing and when to use automated testing.

 

What is Manual Testing?

Manual testing is the process of testing the software manually to find the defects. Tester should have the perspective of an end user and to ensure all the features are working as mentioned in the requirement document. In this process, testers execute the test cases and generate the reports manually without using any automation tools.

Types of Manual Testing:

  1. Black Box Testing
  2. White Box Testing
  3. Unit Testing
  4. System Testing
  5. Integration Testing
  6. Acceptance Testing

Black Box Testing: Black Box Testing is a software testing method in which testers evaluate the functionality of the software under test without looking at the internal code structure. This can be applied to every level of software testing such as Unit, Integration, System and Acceptance Testing.

White Box Testing: White Box Testing is also called as Glass Box, Clear Box, and Structural Testing. It is based on applications internal code structure. In white-box testing, an internal perspective of the system, as well as programming skills, are used to design test cases. This testing usually done at the unit level.

Unit Testing: Unit Testing is also called as Module Testing or Component Testing. It is done to check whether the individual unit or module of the source code is working properly. It is done by the developers in developer’s environment.

System Testing: Testing the fully integrated application to evaluate the systems compliance with its specified requirements is called System Testing AKA End to End testing. Verifying the completed system to ensure that the application works as intended or not.

Integration Testing: Integration Testing is the process of testing the interface between the two software units. Integration testing is done by three ways. Big Bang Approach, Top Down Approach, Bottom-Up Approach

Acceptance Testing: It is also known as pre-production testing.  This is done by the end users along with the testers to validate the functionality of the application. After successful acceptance testing. Formal testing conducted to determine whether an application is developed as per the requirement. It allows customer to accept or reject the application. Types of acceptance testing are Alpha, Beta & Gamma.

There are many types of software testing but here we dealt mainly about Manual and Automation Testing. Here you could read the complete list of software testing types.

When to use Manual Testing?

Exploratory Testing: Exploratory testing will be carried out by domain experts. They perform testing just by exploring the functionalities of the application without having the knowledge of the requirements.

Usability Testing: To verify whether the application is user-friendly or not and was comfortably used by an end user or not. The main focus in this testing is to check whether the end user can understand and operate the application easily or not. An application should be self-exploratory and must not require training to operate it.

Ad-hoc Testing: Ad-hoc testing is quite opposite to formal testing. It is an informal testing type. In Adhoc testing, testers randomly test the application without following any documents and test design techniques. This testing is primarily performed if the knowledge of testers in the application under test is very high. Testers randomly test the application without any test cases or any business requirement document.

When do you prefer Manual Testing over Automation Testing?

We prefer Manual Testing over Automation Testing in the following scenarios

  1. When the project is in initial development stage.
  2. When testing user interface especially their visual aspects.
  3. When exploratory or adhoc testing needs to be performed.
  4. If the project is a short term and writing scripts will be time consuming when compared to manual testing
  5. If the test case is not automatable. Example captcha.

Manual Testing Pros and Cons

Advantages of Manual Testing:

Disadvantages of Manual Testing:

It is not possible to reuse because this process can’t be recorded

What is Automation Testing?

Automation testing is the process of testing the software using an automation tools to find the defects. In this process, executing the test scripts and generating the results are performed automatically by automation tools. Some most popular tools to do automation testing are HP QTP/UFT, Selenium WebDriver, etc.,

Some of the popular automation testing tools

  1. HP QTP(Quick Test Professional)/UFT(Unified Functional Testing)
  2. Selenium
  3. LoadRunner
  4. IBM Rational Functional Tester
  5. SilkTest
  6. TestComplete
  7. WinRunner
  8. WATIR

When to use Automation Testing?

We do Automation testing in the following areas:

Regression Testing: Repeated testing of an already tested program, after modification, to discover any defects introduced or uncovered as a result of the changes in the software being tested or in another related or unrelated software components. So, regression testing is best suitable for automated testing because of frequent code changes and it is beyond the human capacity to execute tests in a timely manner.

Read more about regression testing here

Load Testing:  It is to verify that the system/application can handle the expected number of transactions and to verify the system/application behavior under both normal and peak load conditions. Automated testing is also the best way to complete the testing efficiently when it comes to load testing. It is best suited for automation testing.

Read more about load testing here

Performance Testing – This type of testing determines or validates the speed, scalability, and/or stability characteristics of the system or application under test. Performance is concerned with achieving response times, throughput, and resource-utilization levels that meet the performance objectives for the project or product. It is best suited for automation testing.

Read more about load testing here

The tests which can be done through automated or manual approach:

Integration Testing – Integration Testing is the process of testing the interface between the two software units. Integration testing is done by multiple approaches such as Big Bang Approach, Top-Down Approach, Bottom-Up Approach, and Hybrid Integration approach.

Integration Testing Complete Guide

System Testing – Testing the fully integrated application to evaluate the system’s compliance with its specified requirements is called System Testing AKA End to End testing. Verifying the completed system to ensure that the application works as intended or not.

Unit Testing: Unit Testing is also called Module Testing or Component Testing. It is done to check whether the individual unit or module of the source code is working properly. It is done by the developers in the developer’s environment.

Acceptance Testing: It is also known as pre-production testing.  This is done by the end users along with the testers to validate the functionality of the application. After successful acceptance testing. Formal testing conducted to determine whether an application is developed as per the requirement. It allows the customer to accept or reject the application. Types of acceptance testing are Alpha, Beta & Gamma.

In interviews, you may be asked to answer the following question

Which tests cannot be automated?

Let’s see which tests cannot be automated. Test which take too much effort to automate are

  1. Exploratory Testing
  2. User interface testing
  3. Adhoc Testing

When do you prefer Automation Testing over Manual Testing?

We prefer Manual Testing over Automation Testing in the following scenarios

  1. To handle repetitive and time consuming tasks
  2. To do parallel testing
  3. To do non-functional testing like load, performance, stress testing
  4. To avoid human errors

Automated Testing Pros and Cons

Advantages of automated testing:

Disadvantages of Automated Testing:

Not all the tools support all kinds of testing. Such as windows, web, mobility, performance/load testing

Difference between Manual Testing & Automation Testing (Automation Testing Vs Manual Testing)?

Let’s see the difference between Manual Testing and Automation Testing.

Automation Testing Vs. Manual Testing:

Automation Testing Manual Testing
Automated testing is more reliable. It performs same operation each time. It eliminates the risk of human errors. Manual testing is less reliable. Due to human error, manual testing is not accurate all the time.
Initial investment of automation testing is higher. Investment is required for testing tools. In the long run it is less expensive than manual. ROI is higher in the long run compared to Manual testing. Initial investment of manual testing is less than automation. Investment is required for human resources. ROI is lower in the long run compared to Automation testing.
Automation testing is a practical option when we do regressions testing. Manual testing is a practical option where the test cases are not run repeatedly and only needs to run once or twice.
Execution is done through software tools, so it is faster than manual testing and needs less human resources compared to manual testing. Execution of test cases is time consuming and needs more human resources
Exploratory testing is not possible Exploratory testing is possible
Performance Testing like Load Testing, Stress Testing etc. is a practical option in automation testing. Performance Testing is not a practical option in manual testing
It can be done in parallel and reduce test execution time. Its not an easy task to execute test cases in parallel in manual testing. We need more human resources to do this and becomes more expensive.
Programming knowledge is a must in automation testing Programming knowledge is not required to do manual testing.
Build verification testing (BVT) is highly recommended Build verification testing (BVT) is not recommended
Human intervention is not much, so it is not effective to do User Interface testing. It involves human intervention, so it is highly effective to do User Interface testing.

Conclusion:

Here I am going to conclude this Manual Testing vs Automation Testing post. The real value of manual & automation testing comes when the right type of testing is applied in the right environment. Hope you have understood the difference between manual testing and automation testing and also learnt the advantages and disadvantages of both. If you find any other points which we overlooked, just put it in the comments. We will include and make this post “Manual Testing Vs Automation Testing” updated.

ng:

Disadvantages of Automated Testing:

Not all the tools support all kinds of testing. Such as windows, web, mobility, performance/load testing

Difference between Manual Testing & Automation Testing (Automation Testing Vs Manual Testing)?

Let’s see the difference between Manual Testing and Automation Testing.

Automation Testing Vs. Manual Testing:

Automation Testing Manual Testing
Automated testing is more reliable. It performs same operation each time. It eliminates the risk of human errors. Manual testing is less reliable. Due to human error, manual testing is not accurate all the time.
Initial investment of automation testing is higher. Investment is required for testing tools. In the long run it is less expensive than manual. ROI is higher in the long run compared to Manual testing. Initial investment of manual testing is less than automation. Investment is required for human resources. ROI is lower in the long run compared to Automation testing.
Automation testing is a practical option when we do regressions testing. Manual testing is a practical option where the test cases are not run repeatedly and only needs to run once or twice.
Execution is done through software tools, so it is faster than manual testing and needs less human resources compared to manual testing. Execution of test cases is time consuming and needs more human resources
Exploratory testing is not possible Exploratory testing is possible
Performance Testing like Load Testing, Stress Testing etc. is a practical option in automation testing. Performance Testing is not a practical option in manual testing
It can be done in parallel and reduce test execution time. Its not an easy task to execute test cases in parallel in manual testing. We need more human resources to do this and becomes more expensive.
Programming knowledge is a must in automation testing Programming knowledge is not required to do manual testing.
Build verification testing (BVT) is highly recommended Build verification testing (BVT) is not recommended
Human intervention is not much, so it is not effective to do User Interface testing. It involves human intervention, so it is highly effective to do User Interface testing.

Conclusion:

Here I am going to conclude this Manual Testing vs Automation Testing post. The real value of manual & automation testing comes when the right type of testing is applied in the right environment. Hope you have understood the difference between manual testing and automation testing and also learnt the advantages and disadvantages of both. If you find any other points which we overlooked, just put it in the comments. We will include and make this post “Manual Testing Vs Automation Testing” updated.

Manual Testing Vs Automation Testing in Software Testing

What is Software Testing?

But first, let’s clarify the term ‘Software Testing’.

Software testing is a process, to evaluate the functionality of a software application with an intent to find whether the developed software met the specified requirements or not and to identify the defects to ensure that the product is defect free in order to produce the quality product.

Software Testing is an integral part of any project.

Software testing is categorized into two areas namely Manual Testing & Automation Testing. Both manual testing and automation testing has their own advantages and disadvantages but it’s worth knowing the difference between manual & automation testing and when to you use manual testing and when to use automated testing.

First, we will see what is Manual testing & Automation Testing.

What is Manual Testing?

Manual testing is the process of testing the software manually to find the defects. Tester should have the perspective of an end user and to ensure all the features are working as mentioned in the requirement document. In this process, testers execute the test cases and generate the reports manually without using any automation tools.

Types of Manual Testing:

  1. Black Box Testing
  2. White Box Testing
  3. Unit Testing
  4. System Testing
  5. Integration Testing
  6. Acceptance Testing

Black Box Testing: Black Box Testing is a software testing method in which testers evaluate the functionality of the software under test without looking at the internal code structure. This can be applied to every level of software testing such as Unit, Integration, System and Acceptance Testing.

White Box Testing: White Box Testing is also called as Glass Box, Clear Box, and Structural Testing. It is based on applications internal code structure. In white-box testing, an internal perspective of the system, as well as programming skills, are used to design test cases. This testing usually done at the unit level.

Unit Testing: Unit Testing is also called as Module Testing or Component Testing. It is done to check whether the individual unit or module of the source code is working properly. It is done by the developers in developer’s environment.

System Testing: Testing the fully integrated application to evaluate the systems compliance with its specified requirements is called System Testing AKA End to End testing. Verifying the completed system to ensure that the application works as intended or not.

Integration Testing: Integration Testing is the process of testing the interface between the two software units. Integration testing is done by three ways. Big Bang Approach, Top Down Approach, Bottom-Up Approach

Acceptance Testing: It is also known as pre-production testing.  This is done by the end users along with the testers to validate the functionality of the application. After successful acceptance testing. Formal testing conducted to determine whether an application is developed as per the requirement. It allows customer to accept or reject the application. Types of acceptance testing are Alpha, Beta & Gamma.

There are many types of software testing but here we dealt mainly about Manual and Automation Testing. Here you could read the complete list of software testing types.

When to use Manual Testing?

Exploratory Testing: Exploratory testing will be carried out by domain experts. They perform testing just by exploring the functionalities of the application without having the knowledge of the requirements.

Usability Testing: To verify whether the application is user-friendly or not and was comfortably used by an end user or not. The main focus in this testing is to check whether the end user can understand and operate the application easily or not. An application should be self-exploratory and must not require training to operate it.

Ad-hoc Testing: Ad-hoc testing is quite opposite to formal testing. It is an informal testing type. In Adhoc testing, testers randomly test the application without following any documents and test design techniques. This testing is primarily performed if the knowledge of testers in the application under test is very high. Testers randomly test the application without any test cases or any business requirement document.

When do you prefer Manual Testing over Automation Testing?

We prefer Manual Testing over Automation Testing in the following scenarios

  1. When the project is in initial development stage.
  2. When testing user interface especially their visual aspects.
  3. When exploratory or adhoc testing needs to be performed.
  4. If the project is a short term and writing scripts will be time consuming when compared to manual testing
  5. If the test case is not automatable. Example captcha.

Manual Testing Pros and Cons

Advantages of Manual Testing:

Disadvantages of Manual Testing:

It is not possible to reuse because this process can’t be recorded

What is Automation Testing?

Automation testing is the process of testing the software using an automation tools to find the defects. In this process, executing the test scripts and generating the results are performed automatically by automation tools. Some most popular tools to do automation testing are HP QTP/UFT, Selenium WebDriver, etc.,

Some of the popular automation testing tools

  1. HP QTP(Quick Test Professional)/UFT(Unified Functional Testing)
  2. Selenium
  3. LoadRunner
  4. IBM Rational Functional Tester
  5. SilkTest
  6. TestComplete
  7. WinRunner
  8. WATIR

When to use Automation Testing?

We do Automation testing in the following areas:

Regression Testing: Repeated testing of an already tested program, after modification, to discover any defects introduced or uncovered as a result of the changes in the software being tested or in another related or unrelated software components. So, regression testing is best suitable for automated testing because of frequent code changes and it is beyond the human capacity to execute tests in a timely manner.

Load Testing:  It is to verify that the system/application can handle the expected number of transactions and to verify the system/application behavior under both normal and peak load conditions. Automated testing is also the best way to complete the testing efficiently when it comes to load testing. It is best suited for automation testing.

Performance Testing – This type of testing determines or validates the speed, scalability, and/or stability characteristics of the system or application under test. Performance is concerned with achieving response times, throughput, and resource-utilization levels that meet the performance objectives for the project or product. It is best suited for automation testing.

The tests which can be done through automated or manual approach:

Integration Testing – Integration Testing is the process of testing the interface between the two software units. Integration testing is done by multiple approaches such as Big Bang Approach, Top-Down Approach, Bottom-Up Approach, and Hybrid Integration approach.

Integration Testing Complete Guide

System Testing – Testing the fully integrated application to evaluate the system’s compliance with its specified requirements is called System Testing AKA End to End testing. Verifying the completed system to ensure that the application works as intended or not.

Unit Testing: Unit Testing is also called Module Testing or Component Testing. It is done to check whether the individual unit or module of the source code is working properly. It is done by the developers in the developer’s environment.

Acceptance Testing: It is also known as pre-production testing.  This is done by the end users along with the testers to validate the functionality of the application. After successful acceptance testing. Formal testing conducted to determine whether an application is developed as per the requirement. It allows the customer to accept or reject the application. Types of acceptance testing are Alpha, Beta & Gamma.

In interviews, you may be asked to answer the following question

Which tests cannot be automated?

Let’s see which tests cannot be automated. Test which take too much effort to automate are

  1. Exploratory Testing
  2. User interface testing
  3. Adhoc Testing

When do you prefer Automation Testing over Manual Testing?

We prefer Manual Testing over Automation Testing in the following scenarios

  1. To handle repetitive and time consuming tasks
  2. To do parallel testing
  3. To do non-functional testing like load, performance, stress testing
  4. To avoid human errors

Automated Testing Pros and Cons

Advantages of automated testing:

Disadvantages of Automated Testing:

Not all the tools support all kinds of testing. Such as windows, web, mobility, performance/load testing

Difference between Manual Testing & Automation Testing (Automation Testing Vs Manual Testing)?

Let’s see the difference between Manual Testing and Automation Testing.

Automation Testing Vs. Manual Testing:

Automation Testing Manual Testing
Automated testing is more reliable. It performs same operation each time. It eliminates the risk of human errors. Manual testing is less reliable. Due to human error, manual testing is not accurate all the time.
Initial investment of automation testing is higher. Investment is required for testing tools. In the long run it is less expensive than manual. ROI is higher in the long run compared to Manual testing. Initial investment of manual testing is less than automation. Investment is required for human resources. ROI is lower in the long run compared to Automation testing.
Automation testing is a practical option when we do regressions testing. Manual testing is a practical option where the test cases are not run repeatedly and only needs to run once or twice.
Execution is done through software tools, so it is faster than manual testing and needs less human resources compared to manual testing. Execution of test cases is time consuming and needs more human resources
Exploratory testing is not possible Exploratory testing is possible
Performance Testing like Load Testing, Stress Testing etc. is a practical option in automation testing. Performance Testing is not a practical option in manual testing
It can be done in parallel and reduce test execution time. Its not an easy task to execute test cases in parallel in manual testing. We need more human resources to do this and becomes more expensive.
Programming knowledge is a must in automation testing Programming knowledge is not required to do manual testing.
Build verification testing (BVT) is highly recommended Build verification testing (BVT) is not recommended
Human intervention is not much, so it is not effective to do User Interface testing. It involves human intervention, so it is highly effective to do User Interface testing.

Conclusion:

Here I am going to conclude this Manual Testing vs Automation Testing post. The real value of manual & automation testing comes when the right type of testing is applied in the right environment. Hope you have understood the difference between manual testing and automation testing and also learnt the advantages and disadvantages of both. If you find any other points which we overlooked, just put it in the comments. We will include and make this post “Manual Testing Vs Automation Testing” updated.

Selenium Introduction – IDE, RC, WebDriver and Grid

Selenium Introduction:

Selenium Introduction – It is an open source (free) automated testing suite to test web applications. It supports different platforms and browsers. It has gained a lot of popularity in terms of web-based automated testing and giving a great competition to the famous commercial tool HP QTP (Quick Test Professional) AKA HP UFT (Unified Functional Testing).

Selenium is a set of different software tools. Each tool has a different approach in supporting web based automation testing.

It has four components namely,
i. Selenium IDE (Integrated Development Environment)
ii. Selenium RC (Remote Control)
iii. Selenium WebDriver
iv. Selenium Grid

QTP is a famous automation tool and it was originally developed by Mercury Interactive before HP acquired it. Selenium is used as an antidote in the treatment of mercury intoxication. Jason Huggins (An engineer at ThoughtWorks – the one who introduced Selenium tool) suggested the name of this automation tool as Selenium.

What is Selenium IDE?

Selenium IDE (Integrated Development Environment) is a Firefox plugin. It is the simplest framework in the Selenium Suite. It allows us to record and playback the scripts. Even though we can create scripts using Selenium IDE, we need to use Selenium RC or Selenium WebDriver to write more advanced and robust test cases.

Operation System Support – Windows, Mac OS, Linux
Browser Support – Mozilla Firefox

What is Selenium RC?

Selenium RC AKA Selenium 1. Selenium RC was the main Selenium project for a long time before the WebDriver merge brought up Selenium 2. Selenium 1 is still actively supported (in maintenance mode). It relies on JavaScript for automation. It supports Java, Javascript, Ruby, PHP, Python, Perl and C#. It supports almost every browser out there.

Operation System Support – Windows, Mac OS, Linux, Solaris
Browser Support – Mozilla Firefox, Internet Explorer, Google Chrome, Safari, Opera

What is Selenium WebDriver?

Selenium WebDriver AKA Selenium 2 is a browser automation framework that accepts commands and sends them to a browser. It is implemented through a browser-specific driver. It controls the browser by directly communicating with it. Selenium WebDriver supports Java, C#, PHP, Python, Perl, Ruby.

Operation System Support – Windows, Mac OS, Linux, Solaris
Browser Support – Mozilla Firefox, Internet Explorer, Google Chrome 12.0.712.0 and above, Safari, Opera 11.5 and above, Android, iOS, HtmlUnit 2.9 and above

What is Selenium Grid?

Selenium Grid is a tool used together with Selenium RC to run tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems.

How To Install Selenium IDE, Fire Bug, Fire Path

Before going through how to install Selenium IDE, Fire Bug, Fire Path. Let’s look into in the pre-requisities we need to install Selenium IDE, Fire Bug, Fire Path.

We need to have the following
i. Mozilla Firefox
ii. Active Internet Connection

Download and Install Selenium IDE, Fire Bug, Fire Path

Follow the below steps to complete the installation.

Step 1: Download and Install Selenium IDE
Step 2: Download and Install Fire Bug
Step 3: Download and Install Fire Path

Please be patient. The video will load in some time.

Step 1: Download and Install Selenium IDE

Open Mozilla firefox and go to the below mentioned link

Under Selenium IDE section, click on the link as shown in the below pic.

Now you could see Selenium IDE by navigating through

Tools – Selenium IDE or by typing Ctrl+Alt+S

Step 2: Download and Install Fire Bug

Go to the link mentioned below to install Fire Bug

Now you could see Fire Bug by navigating through

Tools – Web Developer – Firebug – Open Firebug (or) use shortcut key ‘F12’

Step 3: Download and Install Fire Path

Final step is to install Fire Bug. To do this, go to the link mentioned below to install Fire Path

Click on Add to Firefox button

Click on Install button

Click on Restart Now

Now you could see Fire Path by navigating through

Tools – Web Developer – Firebug – Open Firebug (or) use shortcut key ‘F12’

You could find the ‘XPath’ by using ‘FirePath’ as shown below

Selenium WebDriver Architecture | Software Testing Material

Selenium WebDriver Architecture

In this post, we see Selenium WebDriver Architecture in detail. Architecture of Selenium WebDriver is all about how Selenium works internally. We know Selenium is a browser automation tool which interacts with browser and automate end to end tests of a web application.

Don’t Miss: Selenium Tutorial – Learn Step By Step

Selenium is a suite of tools. It consists of Selenium IDE, Selenium RC, Selenium Webdriver, and Selenium Grid

Why WebDriver driver = new FirefoxDriver();

Selenium IDE:

Selenium IDE (Integrated Development Environment) is a Firefox plugin. It is the simplest framework in the Selenium Suite. It allows us to record and playback the scripts. Even though we can create scripts using Selenium IDE, we need to use Selenium RC or Selenium WebDriver to write more advanced and robust test cases.

How to Install Selenium IDE

Selenium RC:

Selenium RC AKA Selenium 1. Selenium RC was the main Selenium project for a long time before the WebDriver merge brought up Selenium 2. Selenium 1 is still actively supported (in maintenance mode). It relies on JavaScript for automation. It supports Java, Javascript, Ruby, PHP, Python, Perl and C#. It supports almost every browser out there.

Note: Selenium RC is officially deprecated.

Selenium WebDriver:

Selenium WebDriver is a browser automation framework that accepts commands and sends them to a browser. It is implemented through a browser-specific driver. It controls the browser by directly communicating with it. Selenium WebDriver supports Java, C#, PHP, Python, Perl, Ruby.

Operation System Support – Windows, Mac OS, Linux, Solaris
Browser Support – Mozilla Firefox, Internet Explorer, Google Chrome 12.0.712.0 and above, Safari, Opera 11.5 and above, Android, iOS, HtmlUnit 2.9 and above

How to Install Selenium WebDriver

Selenium Grid:

Selenium Grid is a tool used together with Selenium RC to run tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems.

Selenium WebDriver is a well designed object oriented API supports many languages such as Java, C#, Python etc. Let’s see what is API and then we move on to know the complete picture of Selenium WebDriver Architecture.

API: 

Application Programming Interface (API) works as an interface between various software components.

Learn API Testing in 10 mins

Selenium WebDriver API:

Selenium Webdriver API helps in communication between languages and browsers. Selenium supports many programming languages such as Java, C#, Python etc., and also it supports multiple browsers such as Google Chrome, Firefox, Internet Explorer etc.,

Real Time Selenium WebDriver Interview Questions

Every browser has different logic of performing actions like loading a page, closing the browser etc.

Here is the Selenium WebDriver Framework Architecture Diagram

 

Selenium WebDriver Architecture

There are four components of Selenium Architecture:

  1. Selenium Client Library
  2. JSON Wire Protocol over HTTP
  3. Browser Drivers
  4. Browsers

Must Read: Top TestNG Interview Questions

Selenium Client Libraries/Language Bindings:

Selenium supports multiple libraries such as Java, Ruby, Python, etc., Selenium Developers have developed language bindings to allow Selenium to support multiple languages. Check out Selenium Libraries in the official site.

JSON WIRE PROTOCOL Over HTTP Client:

JSON stands for JavaScript Object Notation. It is used to transfer data between a server and a client on the web. JSON Wire Protocol is a REST API that transfers the information between HTTP server. Each BrowserDriver (such as FirefoxDriver, ChromeDriver etc.,)  has its own HTTP server.

Browser Drivers:

Each browser contains separate browser driver. Browser drivers communicate with respective browser without revealing the internal logic of browser’s functionality. When a browser driver is  received any command then that command will be executed on the respective browser and the response will go back in the form of HTTP response..

Browsers:

Selenium supports multipe browsers such as Firefox, Chrome, IE, Safari etc.,

Let’s see how Selenium WebDriver works internally

In real time, you write a code in your UI (say Eclipse IDE) using any one of the supported Selenium client libraries (say Java).

Example:

Once you are ready with your script, you will click on Run to execute the program. Based on the above statements, Firefox browser will be launched and it will navigates to softwartestingmaterial website.

Here we see what will happen internally after you click on Run till the launch of Firefox browser.

Once you click on Run, every statement in your script will be converted as a URL with the help of JSON Wire Protocol over HTTP. The URL’s will be passed to the Browser Drivers. (In the above code, we took FirefoxDriver). Here in our case the client library (java) will convert the statements of the script to JSON format and communicates with the FirefoxDriver. URL looks as shown below.

Every Browser Driver uses a HTTP server to receive HTTP requests.  Once the URL reaches the Browser Driver, then the Browser Driver will pass that request to the real browser over HTTP. Then the commands in your selenium script will be executed on the browser.

If the request is POST request then there will be an action on browser

If the request is a GET request then the corresponding response will be generated at the browser end and it will be sent over HTTP to the browser driver and the Browser Driver over JSON Wire Protocol and sends it to the UI (Eclipse IDE).

How To Download And Install Selenium WebDriver (2020)

Before going through how to install Selenium WebDriver. Let’s look into in the pre-requisities we need to install Selenium WebDriver.

We need to have the following
i. Mozilla Firefox
ii. Active Internet Connection

Download Selenium and Install Selenium WebDriver

Follow the below steps to complete the installation.

Step 1: Download and Install JAVA
Step 2: Download and Install Eclipse
Step 3: Download and Install FireBug
Step 4: Download and Install FirePath
Step 5: Download Selenium WebDriver

 

Java version – 10.0.1
Eclipse – Photon
Selenium WebDriver – 3.13.0

Please be patient. The video will load in some time.

Step 1: Download and Install JAVA

Check below video to see “How To Install Java”

Go to the below mentioned link and download latest version of JAVA or click here

Accept the license agreement and choose the right ‘JDK’ file to download based on your system requirement.

Once downloaded. Go ahead and verify the Java version. To do this, open command prompt and type “java -version” and hit enter

Step 2: Download and Install Eclipse

Go to the following link to download eclipse

Download the appropriate file based on your system requirement

Download ‘Eclipse IDE for Java Developers’

Extract the eclipse file which you have downloaded

Right click on ‘eclipse.exe’ and run it as ‘Run as administrator’

Choose specified path to create ‘workspace’ by using ‘Browse’ button.

You could create Java Projects, Packages and Classes in Java Eclipse.

Step 3. Download and Install FireBug

Go to the link mentioned below to install Fire Bug

Click on Add to Firefox button

Click on Install button

Now you could see Fire Bug by navigating through

Tools – Web Developer – Firebug – Open Firebug (or) use shortcut key ‘F12’

Step 4: Download and Install FirePath

Go to the link mentioned below to install Fire Path

Click on Add to Firefox button

Click on Install button

Click on Restart Now

Now you could see Fire Path by navigating through

Tools – Web Developer – Firebug – Open Firebug (or) use shortcut key ‘F12’

You could find the ‘XPath’ by using ‘FirePath’ as shown below

Step 5: Download and Install Selenium WebDriver

Go to the following link to download latest Selenium Java jars (latest Selenium WebDriver jars).

Extract the Selenium file

Open Eclipse and Create Java Project:

File – New – Java Project

Add project name and click on Next followed by Finish.

Create a Package:

Right click on the project you have created and select New – Package

Enter name of the package and click on Finish

Right click on the project you have created and select New – Class

Enter name of the class and click on Finish

Now right click on the newly created project and select ‘Properties’ – ‘Java Build Path’

Select Libraries Tab and click on ‘Add External Jars’

Select all the jars files as shown in the below images and click on Open

Now you could start your first Selenium WebDriver Program.

Top 7 Challenges in Test Automation {Challenges & Limitations in Selenium WebDriver}

Challenges and limitations of Selenium WebDriver 

As we all know Selenium WebDriver is a tool which automates the browser to mimic real user actions on the web. Selenium is a free open source testing tool. Some of the challenges with Selenium WebDriver are as follows

1. We cannot test windows application:

Selenium doesn’t support windows based applications. It supports only web-based applications.

2. We cannot test mobile apps:

We can test on any operating system and browser on the desktop using selenium but we cant deal mobile testing with selenium alone. But there is a solution for this. You can use Appium to handle iOS and Android native, mobile, and hybrid apps using the WebDriver protocol.

3. Limited reporting:

With selenium, you couldn’t generate a good report. But there is a workaround. You can generate reports using TestNG or Extent reports.

4. Handling dynamic Elements:

Some of the web elements are dynamic in nature. If an element’s id is changing on every page load then it bit tricky to handle this in the normal way. We need to handle the dynamic elements with dynamic xpath or dynamic css selectors. Functions like starts-with, contains, ends with, etc., works well to handle dynamic objects.

5. Handling page load:

Some of the web pages are user specific. These user-specific pages load different elements depends on the different user. Sometimes some elements appear depends upon the previous action. If you choose a country from country dropdown then cities related that country will load in the cities dropdown. In runtime selenium script may not identify the element. To overcome this we need to use explicit waits in the script to give the elements enough time to load and to identify the element.

6. Handling pop up windows:

Windows-based pops are part of the operating system. It’s beyond selenium’s capabilities. We could use AutoIT to handle the windows based popups.

7. Handling captcha:

Handling captcha is a limitation in selenium. There are some third-party tools to automate captcha but still, we cannot achieve 100% results.

First Selenium WebDriver Script | Selenium Tutorial

Creating First Selenium WebDriver Script:

Here I don’t want to go in depth to show the first Selenium WebDriver script. I would like to keep it very simple.

Hope you have already installed Selenium WebDriver. If not go through the below mentioned link to download and install Selenium WebDriver.

How To Download And Install Selenium WebDriver

In the first Selenium WebDriver Script, let’s see the below mentioned sceanario using Selenium WebDriver.

Scenario:
To open appropriate URL and verify the title of the home page

Steps:
i. Open Firefox browser
ii. Go to the specified URL
iii. Verify the title and print the output of the title
iv. Close the Firefox browser

Test Data:
URL:
 https://www.softwaretestingmaterial.com
Expected Value: Software Testing Material – A site for Software Testers

To create our first Selenium WebDriver Script, we have to first create a Java Project, Package and Class in Eclipse.

i. Create a Java Project “SoftwareTestingMaterial”
ii. Create a package “seleniumTutorial”
iii. Create a Java Class “FirstSeleniumWebDriverScript”

Test script with an explanation:

(Note: We use // text when we want to comment a single line of code. and use /* text */ when we want to comment multiple lines of code)

Check out the below link for the complete list of Selenium WebDriver tutorials. There is a propaganda in the industry as learning and working on Selenium is very difficult. To be frank, learning Selenium is very easy.

Selenium WebDriver Tutorial

If you are not regular reader of my blog then I highly recommend you to sign up for the free email newsletter using the below link.

Gecko Driver – Launching Firefox Browser In Selenium 3

Gecko Driver – Launching Firefox Browser In Selenium 3:

Selenium WebDriver scripts which were working fine yesterday are not working today?

Why it is not working? Every Selenium Tester has this question. The solution is here. We need to have Gecko Driver to run our scripts with the updated Selenium.

Executing Selenium WebDriver Script in Firefox Browser using Gecko Driver:

Here in this post, we see how to run Selenium WebDriver Script in Firefox Browser using Gecko Driver. Moving forward, we need to have geckodriver.exe and Selenium WebDriver.

Please be patient. The video will load in some time.

Assuming that you have already Installed Selenium WebDriver.

If you want to install Selenium WebDriver, click on the link below to install Selenium WebDriver in few clicks.

How To Download And Install Selenium WebDriver

Each and every browser has its own Driver to execute Selenium WebDriver Scripts. Selenium WebDriver supports browsers such as Mozilla Firefox, Google Chrome, Internet Explorer, Opera, Safari etc.,

Here we are going to see how to run Selenium WebDriver Script in Firefox Browser using Gecko Driver.

Why Gecko Driver?

Selenium has launched Selenium 3 and if you are using Firefox latest version then you may face some issues.

To launch latest version of Firefox Browser using Selnium 3, we need to set a system property “webdriver.gecko.driver” to the path of executable file “geckodriver.exe”

Also find,

  • How to Run Selenium Webdriver Script in Firefox browser – Old Version
  • How to Run Selenium Webdriver Script in Internet Explorer
  • How to Run Selenium WebDriver Script in Chrome Browser

Now, let’s see step by step process

Step 1: Download GeckoDriver.exe

Download the latest release of Gecko driver and unzip the downloaded compressed file and keep it somewhere on a known location on your system.

Step 2: Executing the Test Script in Firefox Browser

Find the sample script (using Java) mentioned below to run test script in Firefox browser using Gecko Driver. Execute it to run the test in Firefox browser which will first open Firefox browser and then open the appropriate URL mentioned in the script

SCRIPT:

Common Issues You May Face:

Issue 1:

If you use old version of mozilla firefox (eg. firefox 45) and latest version of Selenium (Selenium 3.0.1) then you face the below mentioned error.

Exception in thread “main” java.lang.IllegalStateException

Issue 2:

If you use latest version of Mozilla Firefox (eg. Firefox 49) and old version of Selenium (Selenium 2.53) then you face the below mentioned error.

 

Solution – Failed To Launch IE Driver Using Selenium WebDriver

Failed To Launch IE Driver Using Selenium WebDriver?

I heard from many Selenium WebDriver users that they failed to launch IE driver using Selenium WebDriver. Here are the solutions for the common issues most of us might have faced.

Earlier, we have seen “How to Run Selenium WebDriver Script in Internet Explorer browser“. Perhaps, we may failed to launch IE driver using Selenium WebDriver. Error might be similar to the one which we placed in the below screenshot.

Error 1: Exception in thread “main” org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information).

Solution: To fix this error, we need to enable protected mode for all zones.

Follow the below steps to enable protected mode for all zones.

  1. Open Internet Explorer
  2. Go to Tools menu – Internet Options
  3. Select Security Tab
  4. In Select a zone to view or change security settings choose Internet and select the check box of Enable protected mode (requires restarting Internet Explorer).
  5. Similarly, select the check box of Enable protected mode (requires restarting Internet Explorer) for other three such as Local IntranetTrusted sites, and Restricted sites.

Error 2 : Exception in thread “main” org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 200%. It should be set to 100% (WARNING: The server did not provide any stacktrace information).

Solution: To fix this error, we need to set Zoom level of Internet Explorer browser to 100%

Follow the below steps to set Zoom level to 100%

  1. Open Internet Explorer
  2. To to View – Zoom – Select 100%

Do you want to try running the Selenium WebDriver script in Google Chrome. To run the quick start click on the below link.

 

How to Run Selenium WebDriver Script in Chrome browser

Find the sample script (using Java) mentioned below to run test script in Chrome browser. Execute it to run the test in Chrome browser which will first open chrome browser and then open the appropriate URL mentioned in the script

Quick note:

To launch Chrome Browser, we have to do as mentioned below:

1. Set a system property “webdriver.chrome.driver” to the path of executable file “Chromedriver.exe“. If you miss this, you will face an error “The path to the driver executable must be set by the webdriver.chrome.driver system property“.

2. Instantiate a ChromeDriver class

Difference Between FindElement And FindElements Methods

To automate a web application using Selenium WebDriver, we need to locate the elements on a web page. We use different locators depends on our needs to find the elements. Here is a link to the post “Locators in Selenium“. In this post, we discuss two methods to find the elements on a webpage namely findElement and findElements methods.

Let’s see the detailed overview – difference between findElement and findElements methods.

The difference between findElement and findElements methods:

FINDELEMENT() METHOD:

findElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.

Syntax:

FINDELEMENTS() METHOD:

findElements method returns the list of all matching elements. The findElement method throws a NoSuchElementException exception when the element is not available on the page. Whereas, the findElements method returns  an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.

Syntax:

Let’s see a practical example – FindElement and FindElements methods in Selenium WebDriver:

FindElement method:

FindElements method:

How To Install Selenium IDE, Fire Bug, Fire Path

Before going through how to install Selenium IDE, Fire Bug, Fire Path. Let’s look into in the pre-requisities we need to install Selenium IDE, Fire Bug, Fire Path.

We need to have the following
i. Mozilla Firefox
ii. Active Internet Connection

Download and Install Selenium IDE, Fire Bug, Fire Path

Follow the below steps to complete the installation.

Step 1: Download and Install Selenium IDE
Step 2: Download and Install Fire Bug
Step 3: Download and Install Fire Path

Please be patient. The video will load in some time.

Step 1: Download and Install Selenium IDE

Open Mozilla firefox and go to the below mentioned link

Under Selenium IDE section, click on the link as shown in the below pic.

Click on Add to Firefox button

Click on Install button

Click on Restart Now

Now you could see Selenium IDE by navigating through

Tools – Selenium IDE or by typing Ctrl+Alt+S

Step 2: Download and Install Fire Bug

Go to the link mentioned below to install Fire Bug

Click on Add to Firefox button

Click on Install button

Now you could see Fire Bug by navigating through

Tools – Web Developer – Firebug – Open Firebug (or) use shortcut key ‘F12’

Step 3: Download and Install Fire Path

Final step is to install Fire Bug. To do this, go to the link mentioned below to install Fire Path

Click on Add to Firefox button

Click on Install button

Click on Restart Now

Now you could see Fire Path by navigating through

Tools – Web Developer – Firebug – Open Firebug (or) use shortcut key ‘F12’

You could find the ‘XPath’ by using ‘FirePath’ as shown below.

 

Locators in Selenium WebDriver | Selenium Tutorial

Locators in Selenium – Before going ahead, I assume you have already gone through the installation of FireBug and FirePath. If not, check out the link mentioned below:

How To Install Fire Bug, Fire Path

We use FireBug and FirePath to identify the Locators in Selenium

Hope you have already installed Selenium WebDriver. If not go through the below mentioned link to download and install Selenium WebDriver.

How To Download And Install Selenium WebDriver

Selenium identifies the elements to be worked on using the following locators.

Different types of Locators in Selenium are as follows:

i. ID
ii. Name
iii. Class Name
iv. Tag Name
v. Link Text & Partial Link Text
vi. CSS Selector
vii. XPath

Locating elements in WebDriver is done by using the method “findElement(By.locator())“.

We use above mentioned method to locate elements but the locator() part will be replaced with the locator names. Mentioned few examples below for reference.

Here is the link to the post “Difference between findElement and findElements methods”

Let’s see each of the Locators in Selenium in detail:

ID Locator:

ID’s are unique for each element so it is common way to locate elements using ID Locator. As per W3C, ID’s are supposed to be unique on a page and it makes ID’s are the most reliable locator. ID locators are the fastest and safest locators out of all locators.

id = id of the element

Click this link for detailed explanation of ID Locator

Name Locator:

We sometimes use Name locator to identify the elements on our webpage. Locating elements using Name is same as locating elements using ID locator.

These are not unique on a page. If there are multiple elements with the same Name locator then the first element on the page is selected. Test may fail, if another element with the same Name locator is present on the web page or added by the developers in the later stages.

Name = Name of the element

Click this link for detailed explanation of Name Locator

Class Name Locator:

Class Name locator gives the element which matches the values specified in the attribute name “class”.

Click this link for detailed explanation of Class Name Locator

Tag Name Locator:

Tag Name locator is used to find the elements matching the specified Tag Name. It is very helpful when we want to extract the content within a Tag.

Click this link for detailed explanation of Tag Name Locator

Link Text Locator:

If there are multiple elements with the same link text then the first one will be selected. This Link Text locator works only on links (hyperlinks) so it is called as Link Text locator.

Click this link for detailed explanation of Link Text Locator

Partial Link Text:

In some situations, we may need to find links by a portion of the text in a Link Text element. it contains. In such situations, we use Partial Link Text to locate elements.

Click this link for detailed explanation of Partial Link Text Locator

CSS Selector Locator:

There is a debate on the performance between CSS Locator and XPath locator and the debate on the performance of CSS and XPath locator is out of scope of this post. Most of the automation testers believe that using CSS selector makes the execution of script faster compared to XPath locator. This locator is always the best way to locate elements on the page.

Following are the some of the mainly used formats of CSS Selectors.

  • Tag and ID
  • Tag and Class
  • Tag and Attribute
  • Tag, Class and Attribute

Click this link for detailed explanation of CSS Selector Locator

XPath Locator:

XPath is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes, or some other part of an XML document for specific processing. XPath produces reliable locators but in performance wise it is slower (especially in IE older versions) compared to CSS Selector.

 

How To Write Dynamic XPath In Selenium WebDriver | Software Testing Material

How To Write Dynamic XPath In Selenium:

Before learning how to write dynamic XPath in Selenium, we will learn what is XPath locator.

XPath Locator:

XPath is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes, or some other part of an XML document for specific processing. XPath produces reliable locators but in performance wise it is slower (especially in IE older versions) compared to CSS Selector.

Syntax:

Sometimes, we may not identify the element using the locators such as id, class, name, etc. In those cases, we use XPath to find an element on the web page. Check this link to identify the xpath using firepath plugin. At times, XPath may change dynamically and we need to handle the elements while writing scripts. Standard way of writing xpath may not work and we need to write dynamic XPath in selenium scripts. Let’s see different way of writing dynamic XPath in Selenium with examples:

  1. Using Single Slash
  2. Using Double Slash
  3. Using Single Attribute
  4. Using Multiple Attribute
  5. Using AND
  6. Using OR
  7. Using contains()
  8. Using starts_with()
  9. Using text()
  10. Using last()
  11. Using position()
  12. Using index()
  13. Using following xpath axes
  14. Using preceding xpath axes

Learn How To Write Dynamic CSS Selector In Selenium WebDriver [Without Any Tool]

Here is a video tutorial to learn “Creating dynamic XPath in Selenium WebDriver”:

Please be patient. The video will load in some time.

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

Here I am trying to find the element (Email field) on Gmail Login Page

HTML Code: (Gmail login page – Email field)

1. Using Single Slash: 

This mechanism is also known as finding elements using Absolute XPath.

Single slash is used to create XPath with absolute path i.e. the XPath would be created to start selection from the document node/start node/parent node.

Syntax:

2. Double Slash:

This mechanism is also known as finding elements using Relative XPath.

Double slash is used to create XPath with relative path i.e. the XPath would be created to start selection from anywhere within the document. – Search in a whole page (DOM) for the preceding string

Syntax:

3. Single Attribute:

You could write the syntax in two ways as mentioned below. Including or excluding HTML Tag. If you want to exclude HTML Tag then you need to use *

Syntax: 

Note: ‘*‘ after double slash is to match any tag with the desired text

XPath based on above HTML:

4. Multiple Attribute:

Syntax:

XPath based on above HTML:

5. Using AND

Syntax:

XPath based on above HTML:

6. Using OR:

Syntax:

XPath based on above HTML:

7. contains(): It is used to identify an element, when we are familiar with some part of the attributes value of an element.

Syntax:

XPath based on above HTML:

8. starts-with(): It is used to identify an element, when we are familiar with the attributes value (starting with the specified text) of an element.

Syntax:

XPath based on above HTML:

9. text(): This mechanism is used to locate an element based on the text available on a webpage

As per the above image, we could identify the elements text based on the below xpath.

10. last(): Selects the last element (of mentioned type) out of all input element present

To identify the element (last text field ) “Your current email address”, we could use the below xpath.

To identify the element “Year”, we could use the below xpath.

[last()-1] – Selects the last but one element (of mentioned type) out of all input element present

11. position(): Selects the element out of all input element present depending on the position number provided

In below given xpath, [@type=’text’] will locate text field and function [position()=2] will locate text filed which is located on 2nd position from the top.

12. Finding elements using index

By providing the index position in the square brackets, we could move to the nth element. Based on the below xpath, we could identify the Last Name field.

13. following: By using this we could select everything on the web page after the closing tag of the current node

xpath of the FirstName field is as follows

To identify the input field of type text after the FirstName field, we need to use the below xpath.

Here I used, following xpath axes and two colons and then specified the required tag (i.e., input)

To identify just the input field after the FirstName field, we need to use the below xpath.

14. preceding: Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes

xpath of the LastName field is as follows

To identify the input field of type text before the LastName field, we need to use the below xpath.

Here I used, preceding xpath axes and two colons and then specified the required tag (i.e., input).

If you have any queries, please comment below in the comment section. Like this post? Don’t forget to share it!

 

Learn CSS Selector Selenium WebDriver Tutorial [Without Using Any Tools]

CSS Selectors Locator:

There is a debate on the performance of CSS Locator and XPath locator and the debate on the performance of CSS and XPath locator is out of scope of this post. Most of the automation testers believe that using CSS selectors makes the execution of script faster compared to XPath locator. CSS Selector locator is always the best way to locate elements on the page. CSS is always same irrespective of browsers. In this post, I will show you how to find element locators using CSS without using any tools like Firebug or Firepath.

Must Read: How To Write Dynamic XPath in Selenium WebDriver

img: CSS Selector Selenium WebDriver Tutorial

Following are some of the mainly used formats of CSS Selectors.

  • Tag and ID
  • Tag and Class
  • Tag and Attribute
  • Tag, Class, and Attribute
  • Sub-String Matches
    • Starts With (^)
    • Ends With ($)
    • Contains (*)
  • Child Elements
    • Direct Child
    • Sub-child
    • nth-child

Refer to W3C CSS-Selectors for a list of generally available CSS Selectors

Tag and ID:

CSS ID Selector.

Syntax:

Open Mozilla Firefox and navigate to Gmail application.

Open Firebug and inspect the Enter your email input box. Take a note of its Tag and ID. Follow the below screenshot to do so.

Copy the below mentioned script and execute in your system.

 

Value to be added in the By.cssSelector method:

Script:

Tag and Class:

If multiple elements have the same HTML tag and class, then the first one will be recognized.

Syntax:

Open Mozilla Firefox and navigate to Facebook application.

Open Firebug and inspect the Email input box. Take a note of its Tag and Class. Follow the below screenshot to do so.

Copy the below mentioned script and execute in your system.

 

Value to be added in the By.cssSelector method:

Script:

Tag and Attribute:

If multiple elements have the same HTML tag and attribute, then the first one will be recognized. It acts in the same way of locating elements using CSS selectors with the same tag and class.

Syntax:

Open Mozilla Firefox and navigate to Gmail application.

Open Firebug and inspect the Enter your email input box. Take a note of its Tag and Attribute. Follow the below screenshot to do so.

Copy the below mentioned script and execute in your system.

Value to be added in the By.cssSelector method:

Script:

Tag, Class And Attribute:

Syntax:

Open Mozilla Firefox and navigate to Facebook application.

Open Firebug and inspect the Email input box. Take a note of its Tag, Class and Attribute. Follow the below screenshot to do so.

Copy the below mentioned script and execute in your system.

Value to be added in the By.cssSelector method:

Script:

SUB-STRING MATCHES:

CSS in Selenium has an interesting feature of allowing partial string matches using ^$, and *.

Have a look on the below mentioned HTML

Starts with (^): 

To select the element, we would use ^ which means ‘starts with

Syntax:

Value to be added in the By.cssSelector method:

Add the below step in the script to find the element and write a text as “hi”

Ends with ($): 

To select the element, we would use $ which means ‘ends with’

Syntax:

Value to be added in the By.cssSelector method:

Add the below step in the script to find the element and write a text as “hi”

Contains (*): 

To select the element, we would use * which means ‘sub-string

Syntax:

Value to be added in the By.cssSelector method:

Add the below step in the script to find the element and write a text as “hi”

Also we can use ‘contains()’:

Locating Child Elements(Direct Child):

Syntax: parentLocator>childLocator

CSS Locator: div#buttonDiv>button

Explanation: ‘div#buttonDiv>button’ will first go to div element with id ‘buttonDiv’ and then select its child element – ‘button’

Locating elements inside other elements (child or sub-child):

Syntax: parentLocator>locator1 locator2

CSS Locator: div#buttonDiv button

Explanation: ‘div#buttonDiv button’ will first go to div element with id ‘buttonDiv’ and then select ‘button’ element inside it (which may be its child or sub child)

Locating nth Child:

To find nth-child css.

To locate the element with text ‘QTP’, we have to use “nth-of-type”

Similarly, To select the last child element, i.e. ‘Sikuli’, we can use

If you have any queries by finding elements using CSS Selector Selenium, please comment below in the comment section. Like this post? Don’t forget to share it!

How To Handle Drop Down And Multi Select List Using Selenium WebDriver

Handle Drop Down And Multi Select List Using Selenium WebDriver:

To handle drop down and multi select list using Selenium WebDriver, we need to use Select class.

The Select class is a Webdriver class which provides the implementation of the HTML SELECT tag. It exposes several “Select By” and “Deselect By” type methods. We use these methods to select or deselect in the drop down list or multi select object. The Select class is the part of the selenium package.

We need to import the below mentioned library.

Standard syntax of Select Class is as follows:

Example:

or

Note: The Select class starts with capital ‘S’.

To Handle Drop Down And Multi Select List in Selenium we use the following types of Select Methods.

Types of Select Methods:

i. selectByVisibleText Method
ii. selectByIndex Method
iii. selectByValue Method

Types of DeSelect Methods:
i. deselectByVisibleText Method
ii. deselectByIndex Method
iii. deselectByValue Method
iv. deselectAll Method

Let’s see one by one with a sample program:

SelectByVisibleText Method: 

It works based on the ‘visible text‘ provided by us.

Syntax:

Sample program:

SelectByIndex Method:

It works based on the ‘index value‘ provided by us.

Syntax:

Sample program:

SelectByValue Method:

It works based on the ‘value‘ provided by us.

Syntax

Sample program:

 

DeSelect Methods With Examples:

DeselectByVisibleText Method:

It works based on the ‘visible text‘ which we provide

Syntax:

Sample program:

DeselectByIndex Method:

It works based on the ‘index value’ which we provide

Syntax:

Sample program:

DeselectByValue Method:

It works based on the ‘value‘ provided by us.

Syntax:

Sample program:

DeselectAll Method:

It is to deselect all the selected options at once

Syntax:

Sample program:

In order to get the selected option:

Sample program:

In order to get the list of options from a dropdown:

Sample program:

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

How To Upload File Using AutoIT And SendKeys In Selenium WebDriver

In this post we are going to see on how to upload file using AutoIT and sendKeys method in Selenium WebDriver. There are two cases which are majorly used to upload file in Selenium WebDriver such as using SendKeys Method and using AutoIT Script.

Also Read: How To Download File Using AutoIT in Selenium WebDriver

1. Upload file using SendKeys method in Selenium WebDriver:

Its very straightforward. Using sendkeys method, we could easily achieve this. Locate the text box and set the file path using sendkeys and click on submit button.

2. Upload file AutoIt Script in Selenium WebDriver:

If there is no text box to set the file path and only able to click on Browse button to upload the file in the windows popup box then we do upload file using AutoIt tool.

AutoIt Introduction:

AutoIt Tool is an open source tool. It is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!

Now the question is how we do upload file using AutoIT Tool in Selenium WebDriver.

Follow the below steps:

  1. Download Autoit tool from here and install it
  2. Open Programs – Autoit tool – SciTE Script Editor and add the below mentioned AutoIt script in Autoit editor and save it as ‘UploadFile.au3’ in your system
  3. Convert it as ‘UploadFile.exe’
  4. In Eclipse, add the below mentioned Selenium Script and run

Step 1: Download AutoIt tool and install

Step 2: Open SciTE Script editor and add the below mentioned AutoIt script and save it as ‘UploadFile.au3’ in your system.

AutoIt Script:

AutoIt Script Explanation:

Line 1 : WinWaitActive(“File Upload”)

Above line of code changes the focus of cursor on the Window popup box to upload file.

File Upload‘ is the name of the window popup when using Mozilla Firefox. If you want to use other browsers such as Chrome you need to pass the value as ‘Open‘ (‘Open’ is the name of the window popup) and for IE you need to pass the value as ‘File To Upload’ (‘File To Upload’ is the name of the window popup)

Line 2 : Send(“Path of the document”)

Once the window popup is active, it sets the path of the document which needs to be uploaded

Send(“D:\SoftwareTestingMaterial\UploadFile.txt”)

Line 3 : Send(“{ENTER}”)

After that it clicks on Open button which will upload the document

Step 3: Once the file is saved, we need to convert the ‘UploadFile.au3’ to ‘UploadFile.exe’. To do this we need to compile the ‘UploadFile.au3’

Right click on the file ‘UploadFile.au3’ and click on ‘Compile Script’ to generate an executable file ‘UploadFile.exe’

Step 4: In Eclipse, add the below mentioned Selenium Script and run

Given clear explanation in the comments section with in the program itself. Please go through it to understand the flow.

In the above Selenium Script, we did call the AutoIt Script after clicking on the browser button which transfers windows popup box and upload the required file.

Syntax:

Runtime.getRuntime().exec(“D:\\SoftwareTestingMaterial\\AutoIt\\Uploadfile.exe”);

This way we could upload a file using AutoIT

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

How To Handle Javascript Alerts/PopUps In Selenium WebDriver

In this post, we see how to handle javascript alerts/popus. Alerts are basically popup boxes that take your focus away from the current browser and forces you to read the alert message. You need to do some action such as accept or dismiss the alert box to resume your task on the browser.

To handle alerts popupswe need to do switch to the alert window and call Selenium WebDriver Alert API methods.

There are two types of alerts.

  1. Windows Based
  2. Web Based/Browser Based

Here in this post, I confine to Java Script Alerts (A.K.A. Browser/Web Based Alerts).

For Windows Based, Please check the below link.

How To Handle Windows Based Pop-ups Using AutoIT (WILL UPDATE SOON)

To handle Browser based Alerts (Web based alert popups), we use Alert Interface. The Alert Interface provides some methods to handle the popups.

While running the WebDriver script, the driver control will be on the browser even after the alert generated which means the driver control will be behind the alert pop up. In order to switch the control to alert pop up, we use the following command :

Once we switch the control from browser to the alert window. We can use the Alert Interface methods to do required actions such as accepting the alert, dismissing the alert, get the text from the alert window, writing some text on the alert window etc.,

Let’s see the Alert Interface Methods.

We need to Import a package org.openqa.selenium.Alert to handle the alerts in Selenium.

To get a handle to the open alert:

To Click on OK button:

To click on Cancel button.

To get the text which is present on the Alert.

To enter the text into the alert box

To Authenticate by passing the credentials

Sample Program:

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

How To Handle Multiple Windows Using Selenium WebDriver

In this post, we will see how to handle multiple windows using Selenium WebDriver. In real time, we face many scenarios, where an application throws multiple popups. We can easily achieve this using Windows Handles in Selenium WebDriver. We use ‘Switch To’ method which allows us to switch control from one window to other.

Here is a program which handles multiple windows. Given clear explanation in the comments section within the program itself. Please go through it to understand the flow.

 

Mouse Hover Actions Using Actions Class In Selenium

Mouse Hover Actions Using Actions Class:

Sometimes, sub menu items render in DOM only when we mouse hover on main menu. In that case, we face difficulty to click on sub menu item. In order to perform mouse hover actions, we need to chain all of the actions that we want to achieve in one go. To do this we need to make the driver move to the parent element that has child elements and click on the child element.

To achieve this we use Actions class in Selenium WebDriver.

Must Read: Actions Class in Selenium WebDriver

Create object of an Actions Class by passing the WebDriver instance. With the object of the Actions class, driver moves to the main menu and then to the sub menu and click on it.

Let’s see some scenarios.

Mouse hover actions on an element using Actions Class:

Mouse hover actions on a sub-element using Actions Class:

If we want to click on the sub-element, first we need to mouse hover on the parent-element and then sub-element and click on it.

Or

 

How To Perform Right Click Action (Context Click) In Selenium

Perform Right Click Action In Selenium:

In some scenarios, we may need to do right click action / context click on an element to do some actions. We use Actions class in Selenium WebDriver to work on Mouse and Keyboard Actions. Check out the below link for detailed explanation of Actions Class.

Must Read: Actions Class in Selenium WebDriver

Coming back to the current post, here we I take a scenario to do right click action on an element and get the text of an item

Scenario to be automated:

  1. Launch the web browser and open the application
  2. Find the required element and do right click on the element
  3. Go to the options ‘copy’ and get the text of it and print it
  4. Close the browser to end the program

Copy the below mentioned script and work on this scenario.

Given clear explanation in the comments section with in the program itself. Please go through it to understand the flow.

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

How To Perform Double Click Action In Selenium WebDriver

Perform Double Click Action In Selenium:

In some scenarios, we may need to do double click action on a particular element to move further. In such cases, we use Actions class in Selenium WebDriver to work on Mouse and Keyboard Actions. Check out the below link for detailed explanation of Actions Class.

Must Read: Actions Class in Selenium WebDriver

Scenario to be automated:

  1. Launch the web browser and open the application
  2. Find the required element and do double click on the element
  3. Close the browser to end the program

Copy the below mentioned script and work on this scenario.

Given clear explanation in the comments section with in the program itself. Please go through it to understand the flow.

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

Drag And Drop Using Actions Class In Selenium WebDriver

Drag And Drop Using Actions Class:

In some applications, we may face a situation to automate drag and drop an item from one location to another location. We could not achieve these using basic elements. Selenium has provided an “Actions” class to handle this kind of scenarios. We overcome this kind of scenarios such as drag and drop using Actions Class.

To achieve this we use Actions class in Selenium WebDriver. You could find a detailed explanation on Actions in Selenium using below link.

Sample Script:

Given clear explanation in the comments section within the program itself. Please go through it to understand the flow.

If you are not a regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

How To Capture Screenshot Using Selenium WebDriver

Capture Screenshot Using Selenium WebDriver:

Test cases may fail while executing the test cases. While we are executing the test cases manually we just take a screenshot and place in a result repository. The same can be done by using Selenium WebDriver. Here in this post, we see how to capture a screenshot using Selenium WebDriver.

Some of the scenarios we may need to capture screenshot using Selenium WebDriver.

i. Application issues
ii. Assertion Failure
iii. Difficulty to find Webelements on the web page
iv. Timeout to find Webelements on the web page

Syntax to capture and save the screenshot.

Syntax to store it in our local drive

For example:

Below mentioned script shows how to capture a screenshot using Selenium WebDriver.

 

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 

TestNG Parameterization Using DataProviders | TestNG Tutorial

TestNG Parameterization Using DataProviders

Parameterized tests allow developers to run the same test over and over again using different values.

There are two ways to set these parameters:

  • with testng.xml
  • with Data Providers

Let’s see passing parameters using DataProviders:

Specifying parameters in testng.xml might not be sufficient if you need to pass complex parameters, or parameters that need to be created from Java (complex objects, objects read from a property file or a database, etc…). In this case, you can use a Data Provider to supply the values you need to test.  A Data Provider is a method on your class that returns an array of objects.  This method is annotated with @DataProvider:

 

Console Output: