Top 50 Selenium Interview Questions | Selenium Interview Questions

Below are the Top 50 Selenium Interview Questions based on the candidate's experiences and the company's interview pattern.


 

1. What is Automation Testing?

Automation Testing is the process to test any software application through software automation tools like Selenium, QTP, etc.

 

2. What are the advantages of automation testing?

Some basic advantages of automation testing are as follows.

 

1) Automation testing supports both functional and performance test on an application.

2) It supports the execution of repeated test cases.

3) It facilitates parallel execution.

4) It aids in testing a large test matrix.

5) It improves accuracy because there are no chances of human errors.

6) It saves time and money.

 

3. What is Selenium?

Selenium is a portable framework for software testing. Selenium tool facilitates a playback tool for authoring functional tests without the need to learn a test scripting language. Selenium is one of the most widely used open-source Web UI (User Interface) automation testing suites. Jason Huggins developed Selenium in 2004 as an internal tool at Thought Works. Selenium supports automation across different browsers, platforms, and programming languages.

 

4. What are the different components of Selenium?

Selenium is not just a single tool but a suite of software's, each having a different approach to support automation testing. It comprises four major components which include:

 

1) Selenium Integrated Development Environment (IDE)

2) Selenium Remote Control (Now Deprecated)

3) WebDriver

4) Selenium Grid

 

5. How will you find an element using Selenium?

In Selenium every object or control in a web page is referred to as an element, there are different ways to find an element in a web page they are:

1) ID

2) Name

3) Tag

4) Attribute

5) CSS

6) Linktext

7) PartialLink Text

8) Xpath

 

6. ist out the test types that are supported by Selenium?

The test types that can be supported are

a) Functional, Learn More about Functional Testing.

b) Regression

For post-release validation with continuous integration automation tool could be used

a) Jenkins

b) Hudson

c) Quick Build

d) CruiseCont

 

7. Explain what is assertion in Selenium and what are the types of assertion?

Assertion is used as a  verification point. It verifies that the state of the application conforms to what is expected.  The types of assertion are “assert”, “verify”, and “waitFor”.

 

8. Mention what is the use of X-path?

X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.

 

9. Explain the difference between single and double slash in X-path?

Single slash ‘/ ’

1) Single slash ( / ) start selection from the document node

2) It allows you to create ‘absolute’ path expressions

 

Double Slash ‘// ’

1) Double slash ( // ) start selection matching anywhere in the document

2) It enables to create ‘relative’ path expressions

 

10. List out the limitations of Selenium?

Limitations of Selenium are:

1) Selenium supports only web-based applications

2) It does not support the Bitmap comparison

3) For any reporting related capabilities have to depend on third-party tools

4) No vendor support for tool compared to commercial tools like HP UFT

5) As there is no object repository concept in Selenium, maintainability of objects becomes difficult

 

11. What is the difference between verify and assert commands?

1) Assert:  Assert allows checking whether an element is on the page or not. The test will stop on the step that failed if the asserted element is not available. In other words, the test will terminate at the point where the check fails.

 

2) Verify: Verify command will check whether the element is on the page, if it is not then the test will carry on executing.  In verification, all the commands are going to run guaranteed even if any of tests fails.

 

12. What are the advantages of Selenium?

1) It supports C#, PHP, Java, Perl, Python

2) It supports different OS like Windows, Linux, and Mac OS

3) It has got powerful methods to locate elements (Xpath, DOM, CSS)

4) It has a highly developed community supported by Google

 

13. Why testers should opt for Selenium and not QTP?

1) Selenium is more popular than QTP as

2) Selenium is an open-source whereas QTP is a commercial tool

3) Selenium is used especially for testing web-based applications while QTP can be used for testing client-server applications also.

4) Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux, etc. however QTP is limited to Internet Explorer on Windows.

5) Selenium supports many programming languages like Ruby, Perl, Python whereas QTP supports only VB script

 

14. What is the difference between setSpeed() and sleep() methods?

Both will delay the speed of execution.

 

Thread.sleep():  It will stop the current (java) thread for the specified period of time.  It's done only once

 

It takes a single argument in integer format

Ex: thread.sleep(3000)- It will wait for 3 seconds

It waits only once at the command given at sleep

SetSpeed():  For a specific amount of time it will stop the execution for every selenium command.

It takes a single argument in integer format

Ex: selenium.setSpeed(“3000”)- It will wait for 3 seconds

Runs each command  after setSpeed delay by the number of milliseconds mentioned in set Speed

This command is useful for  demonstration purposes or if you are using a slow web application

 

15. What is the same-origin policy? How you can avoid same origin policy?

The “Same Origin Policy” is introduced for security reasons, and it ensures that the content of your site will never be accessible by a script from another site.  As per the policy, any code loaded within the browser can only operate within that website’s domain.

 

To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy, which sits between the browser and application under test and then masks the AUT under a fictional URL

 

16. What are heightened privileges browsers?

The purpose of heightened privileges is similar to Proxy Injection, which allows websites to do something that is not commonly permitted.  The key difference is that the browsers are launched in a special mode called heightened privileges.  By using these browser modes, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.

 

17. How you can use “submit” a form using Selenium ?

You can use “submit” method on the element to submit the form-

element.submit () ;

Alternatively, you can use click method on the element which does form submission.

 

18. Mention what is the difference between Implicit wait and Explicit wait?

Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of time, it will try looking for elements again and again before throwing a NoSuchElementException.  It waits for elements to show up.

Explicit Wait:  It is a one-timer, used for a particular search.

 

19. Which attribute you should consider throughout the script in the frame for “if no frame Id as well as no frame name”?

We can use: driver.findElements(By.xpath(“//iframe”))

This will return list of frames.

You will need to switch to each and every frame and search for the locator which we want.

Then break the loop

 

20. Explain what is the difference between findElements() and findElement()?

find element(): It finds the first element within the current page using the given “locating mechanism”.  It returns a single WebElement

findElements(): Using the given “locating mechanism” find all the elements within the current page.  It returns a list of web elements.

 

21. Explain what are the JUnits annotation linked with Selenium?

The JUnits annotation linked with Selenium are

 

1) @Before public void method() – It will perform the method () before each test, this method can prepare the test

2) @Test public void method() – Annotations @Test identifies that this method is a test method environment

3) @After public void method()- To execute a method before this annotation is used, test method must start with test@Before

 

22. Explain what is Data-driven framework and Keyword driven?

1) Data-driven framework:  In this framework, the test data is separated and kept outside the Test Scripts, while Test Case logic resides in Test Scripts.  Test data is read from the external files ( Excel Files) and are loaded into the variables inside the Test Script.  Variables are used both for input values and for verification values.

2) Keyword-driven framework: The keyword-driven framework requires the development of data tables and keywords, independent of the test automation.  In a keyword-driven test, the functionality of the application under test is documented in a table as well as step-by-step instructions for each test.

 

23. Explain how you can log in into any site if it’s showing any authentication popup for password and username?

Pass the username and password with URL

Syntax-http://username:password@url

ex- http://john:london@www.gmail.com

 

24. What is Object Repository?

An object repository is an essential entity in any UI automation which allows a tester to store all object that will be used in the scripts in one or more centralized locations rather than scattered all over the test scripts.

 

25. Explain how Selenium Grid works?

Selenium Grid sent the tests to the hub. These tests are redirected to Selenium Webdriver, which launches the browser and runs the test.  The entire test suite, it allows for running tests in parallel.

 

26. Can we use the Selenium grid for performance testing?

Yes. But not as effective as a dedicated Performance Testing tool like Loadrunner.

 

27. Explain how you can find broken images on a page using the Selenium Web driver?

To find the broken images on a page using Selenium web driver is

1) Get XPath and get all the links on the page using the tag name

2) On the page click on each and every link

3) Look for 404/500 in the target page title

 

28. Explain how you can handle colors in web driver?

To handle colors in web driver you can use

Use getCssValue(arg0) function to get the colors by sending ‘color’ string as an argument

 

29. Using web driver how you can store a value which is text box?

You can use the following command to store a value which is a text box using web driver

driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

 

30. Explain how you can switch between frames?

To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three possible arguments

 

1) A number:  It selects the number by its (zero-based) index

2) A name or ID: Select a frame by its name or ID

3) Previously found WebElement: Using its previously located WebElement select a frame

 

31. Mention 5 different exceptions you had in the Selenium web driver?

The 5 different exceptions you had in Selenium web drivers are

WebDriverException

NoAlertPresentException

NoSuchWindowException

NoSuchElementException

TimeoutException

 

32. What do you mean by Selenese?

Selenium commands, also known as "Selenese" are the set of commands used in Selenium that run your tests. For example, command - open (URL); launches the desired URL in the specified browser and accepts both relative and absolute URLs.

A sequence of Selenium commands (Selenese) together is known as a test script.

 

33. How to perform right-click an element in Selenium web driver?

We can do right-click in selenium by using Actions class.

 

Actions action = newActions(driver);  

WebElement element = driver.findElement(By.id("elementId"));  

action.contextClick(element).perform();  

 

34. How to perform double-click an element in Selenium web driver?

We can do right-click in selenium by using Actions class.

 

Actions action = newActions(driver);  

WebElement element = driver.findElement(By.id("elementId"));  

action.doubleClick(element).perform();

 

35. Which web driver implementation is fastest?

HTMLUnit Driver implementation is fastest, HTMLUnitDriver does not execute tests on browser but plain HTTP request, which is far quicker than launching a browser and executing tests

 

36. What is the difference between getWindowhandles() and getwindowhandle() ?

getwindowhandles(): It is used to get the address of all the open browser and its return type is Set<String>.

getwindowhandle(): It is used to get the address of the current browser where the control is and return type is a string.

 

37. Explain how you can use recovery scenario with Selenium?

Recovery scenarios depend upon the programming language you use.  If you are using Java then you can use exception handling to overcome the same.  By using “Try Catch Block” within your Selenium WebDriver Java tests

 

38. How can you prepare customized html report using TestNG in hybrid framework ?

There are three ways

1) Junit: With the help of ANT

2) TestNG: Using inbuilt default.html to get the HTML report. Also XST reports from ANT, Selenium, TestNG combinations

3) Using our own customized reports using XSL jar for converting XML content to HTML

 

39. Explain what are the limitations of Selenium IDE?

The limitations of Selenium IDE

1) Exceptional handling is not present

2) Selenium IDE uses only HTML languages

3) External databases reading is not possible with IDE

4) Reading from external files like .txt, .xls is not possible

5) Conditional or branching statements execution like if, else,  select statements is not possible

 

40. In selenium IDE what are the element locators that can be used to locate elements on web page?

In selenium, there are mainly 4 locators that are used

1) X-path locators

2) CSS locators

3) Html id

4) Html name

 

41. Explain how you can debug the tests in Selenium IDE ?

1) Insert a breakpoint from the location where you want to execute step by step

2) Run the test case

3) At the given breakpoint execution will be paused

4) To continues with the next step click on the Blue button

5) To run commands at a time click on the run button

 

42. How will you handle working with multiple windows in Selenium ?

We can use the command selectWindow to switch between windows. This command uses the title of Windows to identify which window to switch to.

 

43. How will you verify the specific position of a web element?

You can use verifyElementPositionLeft & verifyElementPositionTop. It does a pixel comparison of the position of the element from the Left and Top of the page respectively

 

44. Explain what is the main difference between web-driver and RC ?

The main difference between Selenium RC and Webdriver is that selenium RC injects javascript function into browsers when the page is loaded. On the other hand, Selenium Webdriver drives the browser using browser built-in support

 

45. How can we handle pop-ups in RC ?

To handle pop-ups in RC , using selectwindow method, pop-up window will be selected and windowFocus method will let the control from current window to pop-up windows and perform actions according to script

 

46. Explain how you can capture server-side log Selenium Server?

To capture server-side log in Selenium Server, you can use the command

java –jar .jar –log selenium.log

 

47. Other than the default port 4444 how you can run Selenium Server?

You can run Selenium server on java-jar selenium-server.jar-port other than its default port

 

48. How Selenium grid hub keeps in touch with RC slave machine?

At predefined time selenium grid hub keeps polling all RC slaves to make sure it is available for testing.  The deciding parameter is called “remoteControlPollingIntervalSeconds” and is defined in the “grid_configuration.yml” file

 

49. Mention why to choose Python over Java in Selenium?

Few points that favor Python over Java to use with Selenium is,

1) Java programs tend to run slower compared to Python programs.

2) Java uses traditional braces to start and ends blocks, while Python uses indentation.

3) Java employs static typing, while Python is dynamically typed.

4) Python is simpler and more compact compared to Java.

 

50. Mention why do you need Session Handling while working with Selenium?

While working with Selenium, you need Session Handling. This is because, during test execution, the Selenium WebDriver has to interact with the browser all the time to execute given commands. At the time of execution, it is also possible that, before the current execution completes, someone else starts the execution of another script, in the same machine and in the same type of browser. So to avoid such a situation you need Session Handling.