Selenium
How to Download & Install Selenium WebDriver
Selenium installation is a 3 step process: Install Java SDK Install Eclipe Install Selenium...
The following Java Selenium interview questions guide covers 100 most important interview questions for Selenium Webdriver including simple Selenium interview questions as well as Selenium tricky interview questions with answers. This guide has all the selenium interview questions for freshers and Selenium interview questions for experienced candidates to help prepare for the interview.
Following is a curated list of top Selenium Webdriver Interview Questions and Answers:
Selenium is a suite of tools for automated web testing. It is composed of
Web Testing tools Selenium RC and WebDriver are consolidated in single tool in Selenium 2.0
Selenium 3.0 is the latest version of Selenium. It has released 2 beta versions of selenium 3.0 with few of the below changes:
Here are few new features added to Selenium 3.0
Beta 1 updates | Beta 2 updates (Only for Java) |
|
|
|
|
|
|
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
For web based application testing selenium can be used
The test types 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
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”.
X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.
Refer Complete Guide on XPath
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
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.
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
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)
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
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
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.
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
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
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.
You 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 locator which we want.
Then break the loop
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.
The JUnits annotation linked with Selenium are
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.
Pass the username and password with url
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);
Silk Test Tool | Selenium Test Tool |
|
|
|
|
|
|
|
|
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.
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.
Yes. But not as effectively as a dedicated Performance Testing tool like Loadrunner.
WebDriver should be used when requiring improvement support for
Major limitation of injecting capabilities is that “findElement” command may not work as expected.
To find the broken images in a page using Selenium web driver is
To handle colors in web driver you can use
Use getCssValue(arg0) function to get the colors by sending ‘color’ string as an argument
You can use following command to store a value which is text box using web driver
driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);
To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three possible arguments
The 5 different exceptions you had in Selenium web drivers are
You can perform double click by using
You can use “type”command to type in a file input box of upload file. Then, you have to use “Robot” class in JAVA to make file upload work.
HTMLUnit Driver implementation is fastest, HTMLUnitDriver does not execute tests on browser but plain http request, which is far quick than launching a browser and executing tests
To bring control on HTML frame you can use “SwitchTo” frame method-
driver.switchTo().frame(“frameName”);
To specify a frame you can use index number
driver.switchTo().frame(“parentFrame.4.frameName”);
This would bring control on frame named- “frameName” of the 4th sub frame names “parentFrame”
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 string
To switch back from a frame use method defaultContent()
Syntax-driver.switchTo().defaultContent();
Different types of locators are
Above is using PHP. If you are using Java, replace echo with System.out.println
Recovery scenarios depends upon the programming language you use. If you are using Java then you can use exception handling to overcome same. By using “Try Catch Block” within your Selenium WebDriver Java tests
To iterate through options in test script you can loop features of the programming language, for example to type different test data in a text box you can use “for” loop in Java
// test data collection in an array
String[ ] testData = { “test1” , “test2” , “test3” } ;
// iterate through each test data
For (string s: test data) { selenium.type ( “elementLocator”, testData) ; }
There are three ways
To create html test report there are three ways
In Selenium IDE to insert a break point
Selenese is a selenium set of command which are used for running the test
There are three types of Selenese
The limitations of Selenium IDE
Either Selenium IDE can be opened as a pop up window or in side bar
In selenium there are mainly 4 locators that are used
In Selenium IDE you can generate random numbers by using Java Script
type
css=input#s
javascript{Math.random()}
And for
type
css=input#s
javascript{new Date()}
You can use the format option of Selenium IDE to convert tests into another programming language
You can use the “storeTable” command
Example store text from cell 0,2 from an html table
storeTable
Css=#table 0.2
textFromCell
From Selenium IDE single line command can be executed in two ways
In Selenium IDE source view shows your script in XML format
In two ways selenium IDE can be set
To test the locator one can use “Find Button” of Selenium IDE, as you click on it, you would see on screen an element being highlighted provided your element locator is right or or else an error message will be displayed
A regular expression is a special text string used for describing a search pattern. In Selenium IDE regular expression can be used with the keyword- regexp: as a prefix to the value and patterns needs to be included for the expected values.
If you want to “extend” the defualt functionality provided by Selenium Function Library , you can create a Core Extension. They are also called “User Extension”. You can even download ready-made Core Extension created by other Selenium enthusiats.
We can use the command selectWindow to switch between windows. This command uses the title of Windows to identify which window to switch to.
You can use verifyElementPositionLeft & verifyElementPositionTop. It does a pixel comparison of the position of the element from the Left and Top of page respectively
You can use the storeAlert command which will fetch the message of the alert pop up and store it in a variable.
Selenium IDE have limitations in terms of browser support and language support. By using Selenium RC limitation can be diminished.
Selenium IDE does not directly support many functions like condition statements, Iteration, logging and reporting of test results, unexpected error handling and so on as IDE supports only HTML language. To handle such issues Selenium RC is used it supports the language like Perl, Ruby, Python, PHP using these languages we can write the program to achieve the IDE issues.
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 browsers built in support
Advantages of RC are
A collection of libraries and classes is known as Framework and they are helpful when testers has to automate test cases. NUnit, JUnit, TestNG, Bromine, RSpec, unittest are some of the frameworks available 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
Apart from “same origin policy” restriction from js, Selenium is also restricted from exercising anything that is outside browser.
Yes, it is possible when you are not using JAVA testing framework. Instead of using Java testing framework if you are using java client driver of selenium then TestNG allows you to do this. By using “parallel=test” attribute you can set tests to be executed in parallel and can define two different tests, each using different browser.
If you want full automation against different server and client platforms, You need a way to invoke the tests from a command line process, reports that tells you what happened and flexibility in how you create your test suites. TestNG gives that flexibility.
To capture server side log in Selenium Server, you can use command
You can run Selenium server on java-jar selenium-server.jar-port other than its default port
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 “grid_configuration.yml”file
To handle network latency you can use driver.manage.pageloadingtime for network latency
To enter values onto text boxes we can use command sendkeys()
To identify an object using Selenium you can use
isElementPresent(String locator)
isElementPresent takes a locator as the argument and if found returns a Boolean
Few points that favor Python over Java to use with Selenium is,
The challenges faced in Handling Ajax Call in Selenium Webdriver are
Intellij is an IDE that helps you to write better and faster code for Selenium. Intellij can be used in the option to Java bean and Eclipse.
You can customize TestNG report in two ways,
To generate pdf reports, you need Java API IText.
In Selenium WebDriver, Listeners "listen" to the event defined in the selenium script and behave accordingly. It allows customizing TestNG reports or logs. There are two main listeners i.e. WebDriver Listeners and TestNG Listeners.
The types of Listeners in TestNG are,
The desired capability is a series of key/value pairs that stores the browser properties like browser name, browser version, the path of the browser driver in the system, etc. to determine the behavior of the browser at run time.
For Selenium,
For Database Testing in Selenium Webdriver, you need JDBC (Java Database Connectivity) API. It allows you to execute SQL statements.
Selenium is designed to automate web-based applications on different browsers. But to handle window GUI and non-HTML popups in the application you need AutoIT. know more about How to use AutoIT 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 current execution completes, someone else starts execution of another script, in the same machine and in the same type of browser. So to avoid such situation you need Session Handling.
The advantages of Using Git Hub for Selenium are
Prep Up For your Job Interview!!! Go through Selenium Tutorial to be better prepared.
Test your knowledge with Selenium Quiz
Free PDF Download: Selenium Interview Questions & Answers
This detailed Selenium interview questions pdf will help you to clear the doubts about selenium interview questions and will also help you to crack the interview.
Selenium installation is a 3 step process: Install Java SDK Install Eclipe Install Selenium...
There are two types of HTML tables published on the web- Static tables : Data is static i.e....
Selenium Overview: Selenium is an open-source, web Automation Testing tool that supports multiple...
What are Locators? Locator is a command that tells Selenium IDE which GUI elements ( say Text Box,...
As we create software, we always wish it should work differently with a different set of data....
What is Jenkins? Jenkins is the leading open-source continuous integration tool developed by...