Selenium Interview Questions

Q1) What is Selenium and what is composed of?

Selenium is a suite of tools for automated web testing.  It is composed of

  • Selenium IDE (Integrated Development Environment):  It is a tool for recording and playing back.  It is a firefox plugin
  • WebDriver and RC:  It provides the APIs for a variety of languages like Java, .NET, PHP, etc. With most of the browsers Webdriver and RC works.
  • Grid: With the help of Grid you can distribute tests on multiple machines so that test can be run parallel which helps in cutting down the time required for running in-browser test suites

Q2) What is Selenium 2.0?

Web testing tools Selenium RC and WebDriver are consolidated in a single tool in Selenium 2.0

Q3) How will you find an element using Selenium?

In Selenium every object or control in a web page is referred as an elements, there are different ways to find an element in a web page they are - ID - Name - Tag - Attribute - CSS - Linktext - PartialLink Text - Xpath etc

Q4) List out the test types that are supported by Selenium?

For web-based application testing selenium can be used The test types that can be supported are

a)      Functional

b)      Regression

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

a)      Jenkins

b)      Hudson

c)       Quick Build

d)      CruiseCont

Q5) Explain what is an 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 “waifFor”. SeleniumSuite

Q6) 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.

Interested in mastering Selenium Training? Enroll now for FREE demo on Selenium Training in Bangalore.

Q7) Explain the difference between single and double slash in X-path?

Single slash ‘/ ’ - Single slash ( / ) start selection from the document node - It allows you to create ‘absolute’ path expressions Double Slash ‘// ’ - Double slash ( // ) start selection matching anywhere in the document - It enables to create ‘relative’ path expressions

Q8) List out the technical challenges with Selenium?

Technical challenges with Selenium are - Selenium supports only web-based applications - It does not support the Bitmap comparison - For any reporting related capabilities have to depend on third-party tools - No vendor support for tool compared to commercial tools like HP UFT - As there is no object repository concept in Selenium, maintainability of objects becomes difficult

Q9) What is the difference between type keys and type commands?

TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t. Type key populates the value attribute using JavaScript whereas .typekeys() emulates like actual user typing

Q10) What is the difference between verify and assert commands?

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

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 the tests fail.

Q11) What is JUnit Annotations and what are different types of annotations which are useful?

In JAVA a special form of syntactic meta-data can be added to Java source code, this is known as Annotations.  Variables, parameters, packages, methods, and classes are annotated some of the JUnit annotations which can be useful are - Test - Before - After - Ignore - BeforeClass - AfterClass - RunWith

Q12) While using click command can you use screen coordinate? 

To click on a specific part of the element, you would need to use clickAT command.  ClickAt command accepts element locator and x, y co-ordinates as arguments- clickAt (locator, cordString)

Q13)  What are the advantages of Selenium?

It supports C#, PHP, Java, Perl, Python - It supports different OS like Windows, Linux and Mac OS - It has got powerful methods to locate elements (Xpath, DOM , CSS) - It has a highly developer community supported by Google

Q14) Why testers should opt for Selenium and not QTP?

  • Selenium is more popular than QTP as
  • Selenium is an open-source whereas QTP is a commercial tool
  • Selenium is used especially for testing web-based applications while QTP can be used for the testing client-server application also
  • Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux, etc. however QTP is limited to Internet Explorer on Windows.
  • Selenium supports many programming languages like Ruby, Perl, Python whereas QTP supports only VB script

Q15) What are the four-parameter you have to pass in Selenium?

Four parameters that you have to pass in Selenium are - Host - Port Number - Browser - URL

Q16) 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.  Its done only once - It takes a single argument in integer format Ex: thread.sleep(2000)- It will wait for 2 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(“2000”)- It will wait for 2 seconds - Runs each command  after setSpeed delay by the number of milliseconds mentioned in set Speed This command is useful for  demonstration purpose or if you are using a slow web application

Q17) What is same origin policy? How you can avoid same origin policy?

The “Same Origin Policy” is introduced for security reason, and it ensures that 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

Interested in mastering Selenium Training? Enroll now for FREE demo on Selenium Training in New York City.

Q18) What is 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 this browser mode, the Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.

Q19) How you can use “submit” a form using Selenium?

You can use the “submit” method on an element to submit the form- element. submit () ; Alternatively you can use click method on the element which does form submission

Q20) What are the features of TestNG and list some of the functionality in TestNG which makes it more effective?

TestNG is a testing framework based on JUnit and NUnit to simplify a broad range of testing needs, from unit testing to integration testing. And the functionality which makes it efficient testing framework are - Support for annotations - Support for data-driven testing - Flexible test configuration - Ability to re-execute failed test cases

Q21) 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.

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

You can use…..driver.findElements(By.xpath(“//iframe”))…. This will return a 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

Q23) Explain what is the difference between find elements () and find element () ?

find element (): It finds the first element within the current page using the given “locating mechanism”.  It returns a single WebElement find elements () : Using the given “locating mechanism” finds all the elements within the current page.  It returns a list of web elements.

Learn more about Selenium Tutorials For Beginners in this blog post.

Q24) Explain what is the JUnit's annotation linked with Selenium?

The units annotation linked with Selenium are - @Before public void method() – It will perform the method () before each test, this method can prepare the test - @Test public void method() – Annotations @Test identifies that this method is a test method environment - @After public void method()- To execute a method before this annotation is used, test method must start with test@Before

Q25) Explain what is Datadriven framework and Keyword driven? Datadriven 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 for both for input values and for verification values. Keyword-driven framework: The keyword driven frameworks 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.

Q26) Explain how you can login 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-

Q27) Explain how to assert the text of the webpage using selenium 2.0?

WebElement el = driver.findElement(“ElementID”)) //get test from element and stored in text variable String text = el.getText(); //assert text from expected Assert.assertEquals(“Element Text”, text);

Q28) Explain what is the difference between Borland Silk and Selenium? s

Q29) 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.

Q30) 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.  With the entire test suite, it allows for running tests in parallel.

Q31) Can we use the Selenium grid for performance testing?

Yes. But not as effective as a dedicated performance testing tool like Loadrunner.

Q32) What are the testing types that can be supported by Selenium?

Selenium supports the following types of testing:

  1. Functional Testing
  2. Regression Testing

Q33) What are the limitations of Selenium?

The following are the limitations of Selenium: - Selenium supports testing of the only web-based applications - Mobile applications cannot be tested using Selenium - Captcha and Bar code readers cannot be tested using Selenium - Reports can only be generated using third-party tools like TestNG or Junit. - As Selenium is a free tool, thus there is no ready vendor support though the user can find numerous helping communities. - User is expected to possess prior programming language knowledge.

Q34) What is Selenese?

Selenese is the language that is used to write test scripts in Selenium IDE.

Get Selenium Training From Experts

Enroll now for FREE demo on Selenium Training in Dallas.

Q35) What are the different types of locators in Selenium?

The locator can be termed as an address that identifies a web element uniquely within the webpage. Thus, to identify web elements accurately and precisely we have different types of locators in Selenium - ID - ClassName - Name - TagName - LinkText - PartialLinkText - Xpath - CSS Selector - DOM

Q36) What is difference between assert and verify commands? Assert:

Assert command checks whether the given condition is true or false. Let’s say we assert whether the given element is present on the web page or not. If the condition is true then the program control will execute the next test step but if the condition is false, the execution would stop and no further test would be executed.

Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn’t halts i.e. any failure during verification would not stop the execution and all the test steps would be executed.

Q37) When should I use Selenium Grid?

Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.

Q38) What do we mean by Selenium 1 and Selenium 2?

Selenium RC and WebDriver, in a combination, are popularly known as Selenium 2. Selenium RC alone is also referred as Selenium 1.

Q39) What are the different types of waits available in WebDriver?

There are two types of waits available in WebDriver :

  1. Implicit Wait
  2. Explicit Wait

Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command. Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.

Q40) What are the different types of navigation commands?

Following are the navigation commands: navigate().back() – The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history. Sample code: driver.navigate().back(); navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history. Sample code: driver.navigate().forward(); navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements. Sample code: driver.navigate().refresh(); navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL. Sample code: driver.navigate().to(“”);

Q41) How can we handle web based pop up?

WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface. There are the four methods that we would be using along with the Alert interface. - void dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop up window appears. - void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window appears. - String getText() – The getText() method returns the text displayed on the alert box. - void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box. Syntax: // accepting javascript alert                 Alert alert = driver.switchTo().alert(); alert.accept(); For an Indepth knowledge on Selenium, click on below