Selenium Interview Questions Part II

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.

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 :

Learn more about Selenium

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.

How to assert title of the web page?
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.

How to retrieve css properties of an element?

The values of the css properties can be retrieved using a get() method.

Syntax :

How to capture screen shot in WebDriver?
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.

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

Learn about Java in detail

What are the different types of frameworks?

Below are the different types of frameworks:

  • Module Based Testing Framework : The framework divides the entire “Application Under Test” into number of logical and isolated modules. Foreach 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.

  • 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.

  • 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.

  • 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.

  • 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.

  • Behaviour Driven Development Framework : Behaviour Driven Development framework allows automation of functional validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc.

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.

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.

Can captcha be automated?

No, captcha and bar code reader cannot be automated.

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.

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 provide 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

What is Selenium 2.0 ?

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

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

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

  1. Functional

  2. Regression

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

  • Jenkins

  • Hudson

  • Quick Build

  • CruiseCont

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

  • waifFor

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.

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

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.

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)

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

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 specially for testing web based applications while QTP can be used for 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.

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

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

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