Thursday, 9 April 2015

Advanced Selenium Webdriver Interview Questions and Answers in Java

Here is the list of Selenium Interview questions and answers.

How to read data from table? 
You can easily read the data from table using findElements method. Find all the table cells using TD tag and then get the text inside each cell by getText() method or innerText property in HTML DOM.

What all browsers and OS are supported by Selenium? 
Selenium supports below browsers.
  1. Internet Explorer
  2. Google Chrome
  3. Firefox
  4. Safari
  5. Opera
  6. Android browser
  7. iPhone Browser
Operating systems supported by Selenium are -
  1. All Windows OS
  2. Linux
  3. Mac (Apple OS)
  4. Android
  5. IOS
Various Synchronization methods in Selenium Webdriver - implicit wait, page load timeout, explicit wait?
There are 4 ways we can handle synchronization in Selenium.
  1. Implicit
  2. Explicit using wait and expected conditions
  3. Browser Navigation timeout
  4. Script time out 
How to take screenshot in Selenium? 
Selenium provides an interface called TakesScreenshot which has a method getScreenShotAs which can be used to take a screenshot of the application under test.

How to execute JavaScript in Selenium? How many arguments can be passed to executeScript method? 
Selenium webdriver API provides one interface called JavascriptExecutor with a method called executeScript. This method has 2 main arguments. First argument is the javascript code you want to execute on current page and second argument is optional but important. We can pass variable number of web elements as an arguments which can be manipulated in javascript code passed in the first argument.

How to handle multiple browser windows and frames?
We can easily work with multiple windows and frames by switching to them. We can find all open windows in selenium using getWindowhandles method. We can find frame in the web page using name, id or any other method like css or xpath selectors.

How to drag and drop in Selenium Webdriver? 
Selenium webdriver provides Actions class which has many methods to support complex user actions like contextClick, doubleClick, dragAndDrop. 

How to use Selenium Grid?
Selenium grid is used to execute selenium scripts on various environments (OS and browsers) simultaneously and on different machines. Hub acts as a central server which sends the execution requests to the other machines called as nodes. 
Hub server and node server must be up and running. Node machine must be registered with HUB. Depending upon the webdriver capabilities, HUB routes the request to appropriate node to execute the scripts.

Challenges, issues and limitations of Selenium tool? How to handle Captcha? 
We can not handle captcha in Selenium. We can not also automate the Adobe Flash contents on webpages. These are some of the limitations of Selenium.
Other common issues are -
  1. Certificate Errors in IE
  2. Protect mode error
  3. Browser zoom error in IE
  4. Canvas image map
  5. Unsupported command line flag - ignore certificates warning in Chrome
What is the page object model in Selenium? 
Page object model is an alternative way to handle automation project.

Write a complex xpath or css expression? Which one is better?
xpath and css can be used to find any element on the web page. Most of the engineers prefer writing xpath expressions as finding relative elements is very easy in xpath.

How to upload files using AUTOIT Script, Robot?
We can use AUTOIT/Robot/Sikuli code to handle the window dialogs which are not supported by web driver.

Flash automation, silverlight Automation? 
Selenium has no support for these controls. We need to use third party tools to automate these apps.

How to format date and time in Selenium in Java? How to compare dates? 
We can format date in selenium using DateFormat object.

How to append a data to file in Selenium?
We can use File and FileWriter class to work with files in Selenium Webdriver.

Frameworks in Selenium - Data driven, Hybrid, Keyword, BDD - Cucumber, TestNG 
Frameworks are used to speed up the automation testing by developing the test data, reusable functions and reports.

Database testing in Selenium? 
We can use JDBC driver to connect to any database in Java.

How to work with Excel files in Selenium?
We can use JXL or POI library to work with excel files in Selenium.

Find total time of execution in Selenium? 
If we are using custom library, we can log the start and end time of the execution and then find the total execution time by subtracting end time from start time.

How to schedule the Test Suite Execution?
We can schedule the test suite execution using CI tools like hudson(Jenkins), Bamboo. Alternatively, we can use windows scheduler to launch the test execution.

How to send an email stating the execution status to all stakeholders in Selenium? 
We can send mail in Java using javax.mail library.

What is the difference between findElement and findElements?
findElement returns the first matching element. If element is not found, NoElementFoundException is thrown. findElements returns the list of matching web elements. If no element is found, empty list is returned. Exception is not thrown.

What is the difference between Junit and TestNG. What are the various annotations and features? 
TestNG is the new generation testing framework with lot of new useful features as compared to old Junit framework. Using TestNG, we can run the tests in parallel.

Automation of Android apps and Android Browsers using Selenium possible?
We can use  Appium and Selendroid tools to automate mobile applications.

How to handle Ajax calls in Selenium?
When working with Ajax calls, we must be very careful to handle StaleElementStateException. This exception occurs when we refer to the stale (Old) element on page. To handle this error, we need to find the element again after ajax load new elements in the page.

Difference between Selenium and QTP. Competitors to Selenium Webdriver? 
QTP is a licensed tool supporting automation of lot of applications based on .Net, Java, Web and much more. Selenium is a free tool and supports only web application automation testing.

What is desired capabilities?
Capabilities are used to set the values of the browser attributes before we launch any browser using selenium web driver.

Version control tools like SVN, GIT? 
We use version control tools like SVN to track the changes to the files in a project and work in collaboration.

Build tools - Ant, Maven? 
We use these tools to manage build activities for the Java project.

CI tools - Jenkin, Bamboo?
These are continuous integration tools helping in quick deployment of applications, testing them and reporting the issues in the code before it is too late. It helps in getting the application into production quickly and with more quality confidence.

How to identify the frame which does not have Id as well as name?
We can identify the frame using xpath or css selectors as well.

What is the alternative to sendkeys?
We can use JavaScriptExecutor to work with html controls.

How to press TAB key in Selenium?
We can press any keyboard key using Keys class.

What are the Exception that may occur in Selenium Webdriver 
Selenium may throw below exceptions.
  1. InvalidElementStateException
  2. StaleElementReferenceException
  3. ElementNotFoundException
  4. ElementNotVisibleException 
Selenium + Java guide can be helpful to you as well.

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at


  1. Hi Sagar,

    Could you please provide answers to above mentioned questions?

    1. Please check out the answers for selenium web driver questions.


Buy Best Selenium Books