Selenium Interview Questions & Answers

Like this post? Rate it:
1915

Many of you are familiar with Selenium Automation and many of you are also getting your skills updated. In this article, we are going to mention comprehensively the interview questions and answers which you can prepare for Selenium Automation interview. These are designed for beginner and professionals to boost your chances of landing your dream job.

Let’s get started.

1. What is Automation Testing?

Automation testing is a process of automating the manual test process of application under test by using a specific automation tool. In automation tool you create test scripts (we call test cases ‘scripts’ in terms of automation) and execute them repeatedly without any manual intervention.

2. What are the benefits of Automation Testing?

Benefits of automation testing are many:

  • Automated tests take less time to execute than manual tests
  • Automated tests are less error prone than manual tests
  • Automated tests can be written to run without any human intervention
  • Automated tests improves accuracy
  • Automated tests can be run in parallel
  • Automated tests can bring out subtle defects
  • Automated tests save time and money

3. What is Selenium? What are its different components?

Selenium is one of the top Automation testing tools available in the market. Selenium is a suite which is designed to support automation of functional testing of web based applications on a wide range of browsers and various platforms. It supports multiple programming languages as well. Selenium is open source and has an existence of large community, due to this reason it has become one of the most accepted automation tool among the professionals.

Selenium suite has four different components or forms:

  1. Selenium WebDriver: This is the method which is used to automate web applications using the native methods of the browser.
  2. Selenium IDE: This is Selenium Integrated Development Environment. It is a record and playback tool and is distributed as a Firefox plugin for Mozilla browser.
  3. Selenium RC: Selenium Remote Control is basically a server that allows user to create their test scripts in the desired programming language. This component is officially deprecated.
  4. Selenium Grid: By using this component, we can run our test execution in parallel across multiple platforms and environment concurrently.

4. What are the benefits of Selenium?

  • Selenium is open source, hence free to use
  • Selenium supports multiple programming languages: Java, Python, C#, Ruby, etc.
  • Selenium supports multiple browser testing
  • Selenium has a large existing community over the internet and huge amount of resources are available for help
  • Selenium IDE can be used by non-programmers to understand and learn automation scripts
  • Selenium supports testing on distributed environment
  • Selenium has great compatibility for various platforms: Windows, MacOS, Linux, etc.

5. What are the limitations of Selenium?

  • Desktop application testing is not possible, hence only web based application testing is allowed
  • We cannot test mobile apps in Selenium
  • We cannot generate reports directly, we need to integrate third party tools like TestNG and JUnit
  • Manual testers need to learn programming language(s)
  • Only functional and regression testing is possible

6. How many ways are there to locate elements in selenium?

They are called as locators. They are the address of web elements which identify them uniquely within the webpage. We have different locators to find web element precisely:

  • ID
  • XPath
  • CSS Selector
  • Class Name
  • Tag Name
  • Name
  • Link Text
  • DOM

7. What is the priority of the locators?

We have to use the locators with their specified order as shown below:

  1. ID
  2. Name
  3. Class Name
  4. Link Text
  5. CSS Selector
  6. XPath
  7. DOM

8. What is assert and verify commands in Selenium?

Both are used for validation in Selenium. Asserts command check whether the condition is true or false. For example, we are trying to locate the element in the web page and assert command will check whether that element is present or not. Program will execute the next step if the condition is true, otherwise the execution will stop and no further testing is possible. Whereas in verify command, it works the same way as asserts, but it continues to execute irrespective of the conditions being true or false and all the steps will be executed.

9. What is the difference between implicit and explicit wait?

In explicit wait, we make the web driver wait for the specific element for the given time. E.g. we can give command to web driver to wait for the given web element for 5 seconds and for another web element for 10 seconds. Whereas in implicit wait, we make the web driver wait for the same given time for all the web elements present within the web page. E.g. if we set implicit wait of 5 seconds then it will be applicable to all the web elements present within the web page.

10. What is an XPath?

It is a powerful way to parse any HTML code of a web page. XPath is a query language for selecting nodes from XML documents. When you don’t have suitable name or id attribute to locate the element then you have to use XPath.

11. What is the difference between relative and absolute XPath?

In absolute XPath, we locate element by using an XML expression beginning from the root node. We have to specify complete path while using absolute XPath expression. There is a single main disadvantage in that, if even the slightest of change happens in any element then whole absolute XPath fails. Whereas in relative XPath, we provide direct path to the reach the element.

12. What is the disadvantage of Absolute Xpath and why Relative XPath is recommended?

Whenever a simple change occurs in the element our absolute XPath fails to locate. While Relative XPath is not affected by these simple changes due to the fact that it provides direct path to reach those elements. Therefore it is recommended to use Relative XPath over Absolute XPath.

13. Which Add-On is used to automatically generate XPath expressions and CSS Selectors?

Firepath is the name of that add-on. Just by inspecting the element in the webpage one can auto-generate XPath expressions and CSS Selectors for their automation scripts.

14. What is the difference between XPath and CSS Selector?

The fundamental difference is that in XPath expressions we can traverse back in the web page i.e. we can move to parent elements from their child elements. Where in CSS Selectors, we can only move forward in the web page i.e. we cannot locate child from their parents.

15. How do you launch different browsers using Selenium WebDriver?

You can launch browsers by creating an instance of driver of a particular browser:

  • WebDriver driver = new FirefoxDriver();
  • WebDriver driver = new ChromeDriver();
  • WebDriver driver = new InternetExplorerDriver();

16. What is the function of driver.close() and driver.quit() commands?

In selenium, driver.close() method is used to close the window of the web browser which is currently in used or working for testing purpose. In this command, there is no need to provide parameters. Whereas driver.quit() command closes down all the windows of the web browser which the script has opened. Similar to driver.close() command, this command do not require any parameter.

17. What is the difference between single slash (/) and double slash (//) in XPath?

  • Single slash (/) is used for creating Absolute XPath expressions
  • Double slash (//) is used for creating Relative XPath expressions

18. Is there any difference between driver.get(‘URL’) and driver.navigate().to(‘URL’) commands?

No. There is no difference between those two commands, both are used to navigate to a URL specified in the command or passed as a parameter.

19. When do we use Selenium Grid?

We use Selenium Grid when we need to execute test scripts simultaneously on various platforms and browsers to achieve the distributed test execution and to perform testing on the different environment and ultimately saving the time.

20. What are the different types of drivers available in WebDriver?

  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver
  • HtmlUnitDriver
No comments yet. Be the first to add a comment!

Write a comment

Loading...