Top 50 Interview Questions in Selenium

Related Courses

Next Batch : Invalid Date

Next Batch : Invalid Date

Next Batch : Invalid Date

We are so much dependent on the web. And we need to ensure the up-time as well as the functioning of the web apps. Anyways we need testing, and regularly. Selenium happens to be the automation testing tool developed for the testing. And in this blog, you will find various Selenium interview questions that you, as a fresher and experienced, get into the testing domain. You can contact us for your Selenium training. We provide complete Selenium training for Selenium certification. Naresh I Technologies also is the number one computer training institute in Hyderabad and among the top five computer training institutes in India.

Before we start discussing the questions, let's first brief that Manual testing is time-consuming and error-prone. And that is why we opt for the automation testing, and we need the Selenium automation testers.

If we put the technical questions apart, we get Selenium tricky interview questions. That proves we need the Selenium. It's since it is open-source, and we can adapt it. And that is why Selenium is the hero in the web testing arena. You will find that there have been more than 300 percent in the job posting in the past three years. The professionals from various domain companies are looking out for professionals that have the Selenium certification.

You need to learn the Java interview questions if you need to compete as a Selenium tester. So, let's begin our journey. 

The whole set of the Selenium questions is in three parts:

  • The first part is the Selenium basic interview questions meant for the freshers.

  • The Selenium interview questions for the experienced professionals:

  • You also learn the TestNG framework for Selenium.

    Selenium Interview Questions the Basic Level:

    1. Brief some of the advantages and the disadvantages of the Selenium. Compare it to the other testing tools such as the TestComplete and the QTP.

    Differences are as below:

    In Selenium, we do not need the License, though we need a license for the HT QTP and TestComplete. Selenium comes for free, though we need to pay for the HPQTP and TestComplete. Customer support wise, Selenium is weaker as it leverages us with only Open-Source community support. However, the other two provide the complete 24 x 7 support. Selenium requires very high coding skills, and the TestComplete also requires very high coding skills. You can use the Selenium in almost all the environments like Windows, Mac, and Linux. However, you can make use of the HPQTP in the Windows environment only. Whereas you can make use of the TestComplete in Windows 7, 2008, and later versions only.

    2. What changes are in various Selenium versions?

    The Selenium v3 comprises IDE, Grid, and the WebDriver, and the latest version is the Selenium 4. As the WebDriver got introduced, the Selenium RC was deprecated, and we do not use it since then. The "Selenium WebDriver" got introduced in the "Selenium v2." And, there was no "WebDriver" in Selenium v1. The Selenium v1 has three suites of tools: The Selenium IDE, Selenium Grid, and Selenium RC.

    We use the IDE for recording and tests playback. And the WebDriver is used for dynamic web applications tests through the programming interface, and we use the Grid for deploying the tests on the remote host machines.

3. What are various exceptions that you find in the Selenium WebDriver?

Various Exceptions in the Selenium are much like the exceptions in different programming languages. And the most common "exceptions" in the Selenium are:

  • TimeOutException:  If a command does not complete in a set time, then this exception is thrown.

  • ElementNotVisible:  This throws when an element is not visible on the Web Page, but it is present in DOM.

  • NoSuchElementException: Suppose an element with a provided attribute is not on the web page, then this exception is thrown.

    4. What is Selenium is exception test?

    An exception tests the expected exception, which throws within the test class. If you write the test case that way, use @test annotation and brief which exception you want through a mention in the parameters. You need to have a look at the example here. @Test(exceptedException =NoSuchElementException.class).

    You need to keep in mind the syntax used above.

  • StateElementException: If the element gets deleted or no longer attached with the DOM, this exception throws.

    5. Why and how we make use of the Excel Sheet in the project?

    Mention that you use it as a data source for the tests. You can make use of the excel sheet for data set storage while we perform the DataDriven testing. We have two main reasons for doing so.

    While using it as a data source, we store the application URL for each of the environments, need testing as a testing environment, QA environment, and development environment or the environment for staging or pre-production or production environment. You can also store the access credentials for these environments, and on the requirement, you can decode them rather than leaving them unprotected and "plain." Also, we can execute the test cases by listing the whole test case in one column. And in the next column, we can mention yes or No. That indicates whether we want the test case to run or not.

While applying the "excel sheet" for the "DataDriven test," we can store the data for each of the iterations performed for the tests. Like when we test a "web page," we have various sets of input. We pass them through the text box, and we can store them in the excel sheet.

6.  What do you know about POM or the page object model? Can you mention some of the advantages?

It happens to be a design pattern for making an object repository for the web UI elements. And each of these web pages of the application has its page class. It finds the WebEleements on that page and then executes the operations over the WebElements.

Various advantages are:

  • It caters to different operations and the "flows in the UI" starting from verification, which improves the "readability of the code."

  • The "object repositor" is not dependent on test cases. We can make use of it in multiple tests.

  • Above all, we can reuse the code.

8. What do you know about the Page Factory?

Through the Page Factory, we can implement the POM in an optimized manner. And by optimized, we mean that memory usage is "great," and the implementation is in an "object-oriented manner." In POM implementation, we need no package or "cache memory"  if we use the page factory. And we make use of @By(). However, if we do POM implementation without the "Page factory," we need the "page factory package." And, the cache lookup is faster. And we make use of @FindBy().

We use Page Factory for "initialization of the Page Object," or we do the instantiation of the Page Object by ourselves. We can also make the "annotation of the elements" since the describing properties are not all the time informative enough for differentiating an object from others.

We also separate the POM and the Test Methods. We make use of the @FindBy for finding the WebElement and the initElements method for initializing the web element from the class "Page Factory."

@FindBy takes in tagName, partialLinkText, id, name, css, linkText, xpath and className as attributes.

We have various forms of WAIT statements in the Selenium WebDriver. Can you brief about them? Or you can be asked how you ensure WebDriver synchronization?

9. We have two kinds of wait statements, the "implicit Wait" and the second one is the "Explicit."

The first one makes the WebDriver wait for a while through polling the DOM. Once declared, it is accessible for the whole life of the WebDriver instance. Its value is 0 by default. And if you fix a lengthier default, then this behavior polls the DOM periodically based on driver implementation or the browser. You should know that different drivers come with a different set of drivers.

The Explicit makes the execution wait for a while unless a similar condition is leveraged. A few of such conditions attained are:

  • elementToBeSelected

  • elementToBeClickable

  • presenceOfElementLocated

They might ask to curate a code for waiting for a certain element to turn visible on the page. You require writing an alert appearance code.

10. Do you know the JavaScriptExecutor?

You need to state it as an interface that caters to a mechanism for executing the JavaScript via the Selenium WebDriver. It caters to us the "execute script" and executeAsyncScript" methods for running

11. Can you scroll to a specific element in Selenium?

For that, we use scrollIntoView(). You can mention the code as well, which we leave on you to find out. And that is because that will make you learn, and you will grasp the Selenium faster.

12. How can we manage the Keyboard as well as a mouse through Selenium?

We can certainly via the mouse and keyboard events through advanced user interactions API. It has the actions and the action classes required for executing such events. And most common out of them is click and hold (), drag and drop () and source. Target (). The first one, "without leaving the mouse position," clicks. The second one ensures "click" and at the same time hold at the source element location, moves. The third one takes the cursor to the target element location, and then it releases the mouse.

13. How many types of frameworks are there in Selenium? Brief them.

Various frameworks types are:

  • Keyword Driver Framework in which only the operations and the instructions curated in different files such as Excel, XML, CSV, or in some database table, and then 

  • Data-Driven Framework: -

When we have the whole test, data generated via external files such as CSV, Excel, some database table, or XML, and we know it as the Data-Driven framework.

  • Hybrid Framework: This is the combination of both mentioned above.


14. What do we use as the Data source for various frameworks?

Various file types used as Dataset are excel, text, CSV, and XML, etc.

15. What do you mean by Selenese?

It's a selenium command set used for testing the web application. Make use of Actions., Assertions and Accessors. The actions are for performing the operations. The assertions are checkpoints. And, the accessors stores a variable.

16. How POM and PageFactory are different?

POM represents the webpage and holds the functionalities. The Page Factory initializes the web elements in the POM while we initialize the created instance.

17. Can the Selenium take care of Windows Pop-Ups?

Selenium does not support it. We make use of the Alert for displaying the warning in the form of Popup.

Some methods through which achieved are Void dismiss (). We call it when we click in the alert box the cancel button.

 Accept() method is applied when the OK button clicks. The "sendKeys method" sends data to the alert box.

18. What happens to be the Robot class?

We control the mouse and keyboard devices through it. Some of its methods are the KeyPress(), KeyRelease(), MouseMove() and MousePress(). The meaning of these is self-understood. We leave it on you to find it and explain it in your own words.

19. Can we handle multiple windows?

The Window handle holds the unique identifier which stores the windows address. It is a pointer to the windows, and it returns a string value.

  • "get window handle()" gets for us the window handle of the present window.

  • "get window handles()" gets the same for an opened window.

Set: This sets the window handle in the string form.

Switch to: we can switch between the windows through this.

Action: we can execute actions on windows through this.

20. Explain listeners. 

It modifies the system behavior. We customize the reports and logs through it, and they are of two types. The first one is the WebDriver Listener, and the second one is the TestNG listener.

21. Explain Assert and Verify commands.

We compare the actual value of the application with the expected value. And you will not experience a halt in test execution for any value of Verify.

22. How we navigate a web page back and forth?

Suppose d is driver variable. Then we have d.manage.back, d.navigate.forward, d.navigate.to("url") and d.navigate.forward.

Advanced level questions:

23. How can we send the ALT/CONTROL/SHIFT key through Selenium WebDriver?

We hold on to the above keys and then tap on the other button for achieving such functionalities. Hence it's not sufficient to specify these functions alone.

For holding these keys when others get pressed, we need to define the two other methods, which are KeyDown(modifier_key) and in the same format keyUp

Modifier keys are like keys.ALT or similarly SHIFT and CONTROL.

The first perform the modifier key press, and it does not set free the modifier key. The subsequent interactions we assume on keypress.

Also, the second performs the "key release." We make use of both of these methods. We capture the "special function" of a specific key.

TestNG questions for Selenium:

24. Explain TestNG.

It's the Testing framework designed for simplifying the almost whole range of testing requirements right from "unit to integration testing."

25. Can you brief a few advantages of the TestNG?

It leverages us to execute the test methods parallelly. It also helps us in defining the dependencies among the test methods. It assigns the priorities to the test methods. It also supports the parameterized test cases through @Parameters annotation. Via the @DataProvider annotation, we perform data-driven testing. It provides the HTML detailed reports.

26. Brief various annotations in TestNG.

  • @AfterTest

  • @BeforeTest

  • @AfterClass

  • @BeforeClass

  • @AfterMethod

  • @BeforeMethod

  • @AfterSuite

  • @BeforeSuite

  • @AfterGroups

  • @Test

  • @BeforeGroups

27. Mention various testing.xml tags

Test, suite, methods, class, classes

28. Can you place the TestNG tags incorrect order?

Suite, test, classes, class, methods

29. How can you make and run the testing.xml?

In this framework, we create the testing.xml file for creating and handling more than one test class. And we configure our test run, set up the test dependencies, include or exclude the test, package, or "class," and set the priorities in the above file.

30. Explain the importance of the testing.xml file.

We make use of the "testing.xml" file in the "TestNG Selenium project" for configuring the "whole test suite" in one file. Few features are as below:

  • Through this, we can exclude or include the test methods and test group execution.

  • We pass the parameter to the test cases.

  • We leverage adding of add group dependencies.

  • Same thing for test case priorities

  • We also configure the test cases parallel execution.

  • We can parameterize the test cases.

31. How can we pass the parameters to the test cases via this file?

We can declare In this XML file the parameters, and then we can reference the parameters within the source files. Then we can make a java test class known as ParamTest.java and then add the test methods like parameterizedTest() to this class. We provide a string as an input parameter to the "method." And then, we add the annotation @Parameter(: browser") to this particular method. 

32. What is TestNG Assert and write down some of them.

It helps in verifying the test conditions during the test run. Depending on the TestNG assertion, we consider the successful test only when it completes without any exception the test run.

Some of the assertions which are supported by the TestNG are as below:

  • assertEquals(actual, expected)

  • assertEqual( actual, expected, mesg)

And we have assertEqual for the Boolean, and similar we have assertTrue with a different set of parameters: the condition and the messages. One is like assertTrue(condition)

33. What do you mean by the Soft Assert in the TestNG?

Via the Soft Assert, we collect the errors while we perform the test. The soft "assert" does not throw an exception if the asset does not succeed and moves to the next step post assert statement. If an exception occurs, we need the "assert() method," which happens to be the last statement in the @Test, and the test suite moves on with the next test.

34. What is Hard Assert in TestNG?

It throws at once the AssertException once the assert statement fails and the test suite moves to the next test.

35. What do you mean by the exception testing in TestNG?

TestNG provides an option through tracing of the Exception handling code. You verify if the code throws an exception. The exception does the validation. While the test case runs as stated  "expectedException" attribute value together with the @test annotation.

36. What do you mean by the Parameterized testing in TestNG?

It helps the developers in running one test again and again with various values. We can set the parameters in two ways:

And we set parameters in two ways. The first one is through testing.xml, and the second one is through the Data Providers.

However, this is just a glimpse. And many other questions are possible, like how we can create the data-driven framework through the TestNG and how we can "run" test case groups in parallel. Hence, take the above as an introduction, and keep reading books and discover new questions daily. Continuous study will help you grab one of the best jobs.

Some more Questions on Selenium:

We include "10" more questions below, which will give you an idea that there can be numerous questions, and you need to learn the whole Selenium as only then you can craft the best test cases with the help of the Selenium. Some more questions are as below:

37. Which "open-source frameworks" are supported by the Selenium web drivers?

The answer is JUnit and TestNG. 

38. Can you mention some of the locators in Selenium?

Yes, three are ID, ClassName, TagName. We have five more such. They are CSS selector LinkText, XPath, PartialLinkText, and Name.

39. How Does Xpath help a Selenium tester?

It locates the elements. Through it, we navigate via the "attributes and elements" in the XML document to "locate" the web element like button, textbox, image, checkboxes, and a lot more on the web page.

40. When do you make use of the CSS selector?

We use it when the ID and the name locators do not turn out to be unique. And similarly, we make use of XPath when we don't have any preferred locators.

41. How are the Single slash and the Double slash different?

By single slash, we mean the XPath with an absolute path, and by a double slash, we mean XPath with a "relative path."

42. How the "Assert" and the verify differ in the case of Selenium?

If the "assert" is True, then the program executes the next test step. Though, It does not if it's false.

However, the program executes no matter the Verify is true or false.

43. How Soft Asset and hard assert are different?

The first collects the errors during @Test, and it does not throw an exception if the assert fails and moves on with the next step post assert statement.

The "Hard Assert" throws an AssertException on the failure of the assert statement. And the suite moves on with the next test.

44. How the setSpeed() and the sleep() methods differ?

Both delays the "execution speed." The first applies the delay time before the operation. Like setSpeed(4000). It waits for 4 seconds. And the second one sets the wait time only once when we call the Selenium script. Like sleep (3000) waits for 3 seconds.

55. What do you mean by verification points?

We make use of the Selenese Verify as the "verification point" and the "assert commands." We don't have any pre-built feature in WebDriver for verification points. We use a coding style. And some of them are for checking page title, checking text, and checking elements like drop-down, button, etc.

Final Tip:

You need to understand that ultimately you have to write the test cases in Selenium and execute them. However, you cannot do that if you do not have complete knowledge. You need detailed knowledge for this, and hence you should learn Java and all the nitty-gritty of the Selenium if you want to succeed as a Selenium tester. 

You can contact Naresh I Technologies for your Selenium online training. We provide Selenium training in Hyderabad and USA, and in fact, you can contact us from any part of the world through our phone or online form on our site. Just fill it and submit it, and one of our customer care executives will be contacting you. And what else you get:

  • You have the freedom to choose from Selenium online training and classroom training.

  • Chance to study from one of the best faculties and one of the best Selenium training institutes in India

  • Nominal fee affordable for all

  • Complete training 

  • You get training for tackling all the nitty-gritty of Selenium.

  • Both theoretical and practical training.

  • And a lot more is waiting for you.

You can contact us anytime for your Selenium training and from any part of the world. Naresh I Technologies caters to one of the best Selenium training in India.