Top most important selenium interview questions and answers by Experts:
Here is a list of Top most important selenium interview questions and answers by Experts.If you want to download selenium interview questions pdf free ,you can register with RVH techguru. Our experts prepared these selenium interview questions to accommodate freshers level to most experienced level technical interviews.
If you want to become an expert in selenium ,Register for selenium online training here.
1) What is Automation Testing?
Automation testing or Test Automation is a process of automating the manual process to test the application/system under test. Automation testing involves use to a separate testing tool which lets you create test scripts which can be executed repeatedly and doesn’t require any manual intervention.
2) What are the benefits of Automation Testing?
Benefits of Automation testing are:
1. Supports execution of repeated test cases
2. Aids in testing a large test matrix
3. Enables parallel execution
4. Encourages unattended execution
5. Improves accuracy thereby reducing human generated errors
6. Saves time and money
3) Why should Selenium be selected as a test tool?
1. is free and open source
2. have a large user base and helping communities
3. have cross Browser compatibility (Firefox, chrome, Internet Explorer, Safari etc.)
4. have great platform compatibility (Windows, Mac OS, Linux etc.)
5. supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.)
6. has fresh and regular repository developments
7. supports distributed testing
4) What is Selenium? What are the different Selenium components?
Selenium is one of the most popular automated testing suites. Selenium is designed in a way to support and encourage automation testing of functional aspects of web based applications and a wide range of browsers and platforms. Due to its existence in the open source community, it has become one of the most accepted tools amongst the testing professionals.
Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason it is referred to as a Suite. Each of these tools is designed to cater different testing and test environment requirements.
The suite package constitutes of the following sets of tools:
• Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
• Selenium Remote Control (RC) – Selenium RC is a server that allows user to create test scripts in a desired programming language. It also allows executing test scripts within the large spectrum of browsers.
• Selenium WebDriver – WebDriver is a different tool altogether that has various advantages over Selenium RC. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
• Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently.
5) What are the testing types that can be supported by Selenium?
Selenium supports the following types of testing:
1. Functional Testing
2. Regression Testing
6) What are the limitations of Selenium?
Following are the limitations of Selenium:
• Selenium supports testing of 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.
7) When should I use Selenium IDE?
Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.
8) What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE.
9) What are the different types of locators in Selenium?
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:
• CSS Selector
10) 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.
11) What is an Xpath?
Xpath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, Xpath can be used to locate HTML elements.
The fundamental behind locating elements using Xpath is the traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.
12) What is the difference between “/” and “//” in Xpath?
Single Slash “/” – 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.
Double Slash “//” – 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.
13) What is Same origin policy and how it can be handled?
The problem of same origin policy disallows to access the DOM of a document from an origin that is different from the origin we are trying to access the document.
Origin is a sequential combination of scheme, host and port of the URL. For example, for a URL http:// http://www.softwaretestinghelp.com/resources/, the origin is a combination of http, softwaretestinghelp.com, 80 correspondingly.
So, In order to handle same origin policy, Selenium Remote Control was introduced.
14) What is Selenium 2.0 ?
Web testing tools Selenium RC and WebDriver are consolidated in single tool in Selenium 2.0
15) 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
• PartialLink Text
• Xpath etc
16) List out the test types that are supported by Selenium?
For web based application testing selenium can be used
The test types can be supported are
For post release validation with continuous integration automation tool could be used
c) Quick Build
17) 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.
18) 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
19) 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
20) What is the difference between type keys and type commands ?
21) What is the difference between verify and assert commands?
Assert: Assert allows to check 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 terminated at the point where 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 test fails.
22) 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 know as Annotations. Variables, parameters, packages, methods and classes are annotated some of the JUnit annotations which can be useful are
23) While using click command can you use screen coordinate?
To click on specific part of element, you would need to use clickAT command. ClickAt command accepts element locator and x, y co-ordinates as arguments-
clickAt (locator, cordString)
24) What are the advantages of Selenium?
• It supports C#, PHP, Java, Perl, Phython
• It supports different OS like Windows, Linux and Mac OS
• It has got powerful methods to locate elements (Xpath, DOM , CSS)
• It has highly developer community supported by Google
25) What are the four parameter you have to pass in Selenium?
Four parameters that you have to pass in Selenium are
• Port Number
26) 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 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
27) 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
28) What is heightened privileges browsers?
The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that are not commonly permitted. The key difference is that the browsers are launced in a special mode called heightened privileges. By using these browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.
29) How you can use “submit” a form using Selenium ?
You can use “submit” method on element to submit form-
element.submit () ;
Alternatively you can use click method on the element which does form submission
30) 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
31) 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 element 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.
32) Which attribute you should consider throughout the script in frame for “if no frame Id as well as no frame name”?
You can use…..driver.findElements(By.xpath(“//iframe”))….
This will return list of frames.
You will ned to switch to each and every frame and search for locator which we want.
Then break the loop
33) 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
findElements () : Using the given “locating mechanism” find all the elements within the current page. It returns a list of web elements.
34) Explain what are the JUnits annotation linked with Selenium?
The JUnits 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
35) 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.
Keyworddriven 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.
36) 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
• ex- http://creyate:email@example.com
37) Explain how to assert text of webpage using selenium 2.0 ?
WebElement el = driver.findElement(By.id(“ElementID”))
//get test from element and stored in text variable
String text = el.getText();
//assert text from expected
Assert.assertEquals(“Element Text”, text);
38) What is Object Repository ?
An object repository is an essential entity in any UI automations 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.
39) Explain how Selenium Grid works?
Selenium Grid sent the tests to the hub. These tests are redirected to Selenium Webdriver, which launch the browser and run the test. With entire test suite, it allows for running tests in parallel.
30) Can we use Selenium grid for performance testing?
Yes. But not as effectively as a dedicated performance testing tool like Loadrunner.
31) 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.
32) 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.
33) Which is the latest Selenium tool?
34) How do I launch the browser using WebDriver?
The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
35) What are the different types of Drivers available in WebDriver?
The different drivers available in WebDriver are:
36) 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.
37) How to type in a textbox using Selenium?
User can use sendKeys(“String to be entered”) to enter the string in the textbox.
WebElement username = drv.findElement(By.id(“Email”));
// entering username
38) How can you find if an element in displayed on the screen?
WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isDisplayed();
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
39) How can we get a text of a web element?
Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.
String Text = driver.findElement(By.id(“Text”)).getText();
40) How to select value in a dropdown?
Value in the drop down can be selected using WebDriver’s Select class.
Select selectByValue = newSelect(driver.findElement(By.id(“SelectID_One”)));
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
Select selectByIndex = newSelect(driver.findElement(By.id(“SelectID_Three”)));
41) 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.
navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history.
navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements.
navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL.
42) How to click on a hyper link using linkText?
The command finds the element using link text and then click on that element and thus the user would be re-directed to the corresponding page.
The above mentioned link can also be accessed by using the following command.
The above command find the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element with the specified substring and then clicks on it.
43) How to handle frame in WebDriver?
An inline frame acronym as iframe is used to insert another document with in the current HTML document or simply a web page into a web page by enabling nesting.
Select iframe by id
driver.switchTo().frame(“ID of the frame“);
Locating iframe using tagName
Locating iframe using index
frame(Name of Frame)
driver.switchTo().frame(“name of the frame”);
Select Parent Window
44) When do we use findElement() and findElements()?
findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched.
WebElement element =driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.
List <WebElement> elementList =driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
45) How to find more than one web element in the list?
At times, we may come across elements of same type like multiple hyperlinks, images etc arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.
1 // Storing the list
2 List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
3 // Fetching the size of the list
4 int listSize = elementList.size();
5 for (int i=0; i<listSize; i++)
7 // Clicking on each service provider link
9 // Navigating back to the previous page that stores link to service providers
46) What is the difference between driver.close() and driver.quit command?
close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value.
quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.
47) Can Selenium handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing. Therefore, windows pop up cannot be handled using Selenium.
48) 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.
Alert alert = driver.switchTo().alert();
49) How can we handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing, that means, it doesn’t support testing of windows based applications. However Selenium alone can’t help the situation but along with some third party intervention, this problem can be overcome. There are several third party tools available for handling window based pop ups along with the selenium like AutoIT, Robot class etc.
50) How to assert title of the web page?
//verify the title of the web page
assertTrue(“The title of the window is incorrect.”,driver.getTitle().equals(“Title of the page”));
51) How to mouse hover on a web element using WebDriver?
WebDriver offers a wide range of interaction utilities that the user can exploit to automate mouse and keyboard events. Action Interface is one such utility which simulates the single user interactions.
Thus, In the following scenario, we have used Action Interface to mouse hover on a drop down which then opens a list of options.
1 // Instantiating Action Interface
2 Actions actions=new Actions(driver);
3 // howering on the dropdown
4 actions.moveToElement(driver.findElement(By.id(“id of the dropdown”))).perform();
5 // Clicking on one of the items in the list options
6 WebElement subLinkOption=driver.findElement(By.id(“id of the sub link”));
52) What is a framework?
Framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.
53) What are the advantages of Automation framework?
Advantage of Test Automation framework
• Reusability of code
• Maximum coverage
• Recovery scenario
• Low cost maintenance
• Minimal manual intervention
• Easy Reporting
54) What are the different types of frameworks?
Below are the different types of frameworks:
1. Module Based Testing Framework: The framework divides the entire “Application Under Test” into number of logical and isolated modules. For each module, we create a separate and independent test script. Thus, when these test scripts taken together builds a larger test script representing more than one module.
2. Library Architecture Testing Framework: The basic fundamental behind the framework is to determine the common steps and group them into functions under a library and call those functions in the test scripts whenever required.
3. Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate the test script logic and the test data from each other. It lets the user store the test data into an external database. The data is conventionally stored in “Key-Value” pairs. Thus, the key can be used to access and populate the data within the test scripts.
4. Keyword Driven Testing Framework: The Keyword driven testing framework is an extension to Data driven Testing Framework in a sense that it not only segregates the test data from the scripts, it also keeps the certain set of code belonging to the test script into an external data file.
5. Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.
6. Behavior Driven Development Framework: Behavior Driven Development framework allows automation of functional validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc.
55) How can I read test data from excels?
Test data can efficiently be read from excel using JXL or POI API.See detailed tutorial here.
56) Can WebDriver test Mobile applications?
WebDriver cannot test Mobile applications. WebDriver is a web based testing tool, therefore applications on the mobile browsers can be tested.
60) Can captcha be automated?
No, captcha and bar code reader cannot be automated.
61) What is Object Repository? How can we create Object Repository in Selenium?
Object Repository is a term used to refer to the collection of web elements belonging to Application Under Test (AUT) along with their locator values. Thus, whenever the element is required within the script, the locator value can be populated from the Object Repository. Object Repository is used to store locators in a centralized location instead of hard coding them within the scripts.
In Selenium, objects can be stored in an excel sheet which can be populated inside the script whenever required.