Google News
logo
Selenium Interview Questions
Selenium is an open source umbrella project for a range of tools and libraries aimed at supporting browser automation. Selenium is a portable framework for software testing. Selenium tool facilitates with a playback tool for authoring functional tests without the need to learn a test scripting language.
 
Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite. Jason Huggins developed Selenium in 2004 as an internal tool at Thought Works. Selenium supports automation across different browsers, platforms, and programming languages.
Selenium is not just a single tool but a suite of software's, each having a different approach to support automation testing. It comprises of four major components which include :

Selenium Integrated Development Environment (IDE) : It is a Firefox/Chrome plug-in that was developed to speed up the creation of automation scripts. It records the user actions on the web browser and exports them as a reusable script.
 
Selenium Remote Control (RC) : RC is a server that allows users to write application tests in various programming languages. The commands from the test script are accepted by this server and are sent to the browser as Selenium core JavaScript commands. The browser then behaves accordingly.
 
Selenium WebDriver : WebDriver is a programming interface that helps create and run test cases. It makes provision to act on web elements. Unlike RC, WebDriver does not require an additional server and interacts natively with the browser applications.
 
Selenium Grid : The grid was designed to distribute commands to different machines simultaneously. It allows the parallel execution of tests on different browsers and different operating systems. It is exceptionally flexible and is integrated with other suite components for simultaneous execution.
Lists of top 10 used automation testing tools for Functional Automation are as follows :
 
* Teleric Test Studio, Developed by Teleric.
* TestingWhiz
* HPE Unified Functional Testing (HP - UFT formerly QTP)
* Tosca Testsuite
* Watir
* Quick Test Professional, provided by HP.
* Rational Robot, provided by IBM.
* Coded UI, provided by Microsoft.
* Selenium, open source.
* Auto It, Open Source.
Selenium supports various operating systems, browsers and programming languages. Following is the list :
 
Programming Languages : C#, Java, Python, PHP, Ruby, Perl, JavaScript.

Operating Systems : Android, iOS, Windows, Linux, Mac, Solaris.

Browsers : Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari, etc.
Following are the advantages of using Selenium for automated testing :
 
Open-Source : Selenium's greatest strength, as previously said, is that it is a freeware and portable tool. There are no out-of-pocket expenses. The utility can be downloaded for free, and community-based help is also accessible.

Language assistance : Java, Perl, Python, C#, Ruby, Groovy, JavaScript, and other languages are supported by Selenium. It has its own script, yet it is not constrained by it. It can work with a variety of languages, depending on the developers' and testers' preferences.

Compatible with a variety of operating systems : Selenium may run on a variety of operating systems, including Windows, Mac OS X, Linux, and UNIX. A customized testing suite can be constructed on any platform and then executed on another using the Selenium suite of products. For example, you may write test cases in Windows and run them on a Linux system with ease.

Browser compatibility : Selenium is compatible with a variety of web browsers, including Internet Explorer, Chrome, Firefox, Opera, and Safari. When running tests and testing them across multiple browsers at the same time, this becomes really useful.

Programming languages and framework support : Selenium works with a variety of programming languages and frameworks. For source code compilation, it can, for example, integrate with ANT or Maven frameworks. It may also be used to test apps and generate reports using the TestNG framework. Continuous Integration (CI), can integrate with Jenkins or Hudson, and it can also integrate with other open-source tools to offer other functionalities.

Tests on a variety of devices : On Android, iPhone, and Blackberry, Selenium Test Automation can be used to automate mobile web applications testing. This can aid in the generation of necessary results and the ongoing resolution of bugs present in the application.

Regular updates : Selenium support is based on a community, which allows for frequent updates and upgrades. These upgrades are simple to install and don't require any special training. Selenium is thus both resourceful and cost-effective.

Selenium suites with a lot of content : Selenium is more than just a single tool or utility; it's a full set of numerous testing tools that's why it's called a Suite. Each tool is tailored to specific testing needs and test environment constraints. Selenium also includes features such as Selenium IDE, Selenium Grid, and Selenium Remote Control (RC).

Ease with which it can be implemented : Selenium has a user-friendly interface that makes it simple to develop and perform tests. Its open-source capabilities allow users to script their own extensions, making them simple to create, alter actions, and manipulate at a high level. Selenium's reporting features are also one of the reasons for its popularity, as it allows testers to extract results and take action based on them.
Unavailability of reliable tech support : Since Selenium is an open-source tool, it does not have dedicated tech support to resolve the user queries. 

Tests web applications only : Selenium needs to be integrated with third-party tools like Appium and TestNG to test desktop and mobile applications.
Limited support for image testing.

No built-in reporting and test management facility : Selenium has to be integrated with tools like TestNG, or JUnit among others to facilitate test reporting and management.

May require the knowledge of programming languages : Selenium WebDriver expects the user to have some basic knowledge about programming. 
A significant change under the hood for WebDriver is the complete W3C compliance of the WebDriver APIs. This standardization will eliminate the need for encoding and decoding the API requests by the JSON wire protocol in Selenium 3 and earlier versions for communication between browsers and test scripts. This means the WebDriver will now interact directly with the target browser.
 
This standardization will result in more stable cross browser tests. However, the change in protocol won’t impact existing users as popular browser drivers like ChromeDriver and GeckoDriver have completely adopted W3C protocols. In a nutshell, JSON wire protocol is deprecated in Selenium 4.
The earlier version of Selenium Grid was complex to set up and rigid in terms of scaling.
 
The new Selenium Grid comes with Docker support. This will enable developers or testers to spin up the containers rather than setting up heavy virtual machines. Moreover, it is redesigned in a way that will allow QAs to deploy the grid on Kubernetes for better scaling.
 
Managing Selenium Grid is now smooth and easy as there will no longer be any need to set up and start hubs and nodes separately.
 
Teams or individual testers can now deploy the grid in three modes:
 
* Standalone mode
* Hub and Node
* Fully distributed

Unlike in earlier versions, the Grid will now support IPv6 addresses and one can communicate with the Grid using the HTTPS protocol. In Grid 4, the configuration files used for spinning up the grid instances can be written in TOML (Tom’s Obvious, Minimal Language) which will make it easier for humans to understand.
 
The Grid in Selenium 4 also comes with an enhanced user-friendly GUI. Overall, the revamped Selenium Grid will enhance the DevOps process as it provides compatibility with tools like Azure, AWS, and more.
Most QA engineers using the Selenium tool suite are familiar with the popular record and playback tool – Selenium IDE. This Selenium IDE was earlier available just as a Firefox add-on. Later, it got deprecated with the introduction of the latest Firefox versions. This is because the add-ons in the latest Firefox (ver. 55) were standardized under the Web Extension mechanism.
 
With Selenium 4, the IDE is revived and now its add-on is available for major web-browsers like Firefox and Chrome. The add-on for Selenium IDE is now also available on the MS store.
 
The new Selenium 4 IDE provides some notable features like :
 
* Improved GUI for intuitive user experience.

* The new IDE also comes bundled with a SIDE tool aka Selenium IDE runner. It allows QAs to run .side projects on a node.js platform. This SIDE runner also enables individual QAs to run cross browser tests on local or Cloud Selenium Grid.

* Improved control flow mechanism that enables testers to write better “while” and “if” conditions.

* The new IDE comes with an enhanced element locator strategy (Like a backup strategy) which helps locate an element in case the web element couldn’t be located. It will result in the creation of stable test cases.

* The code for test cases recorded using Selenium IDE can be exported in the desired language binding like Java, C#, Python, .NET, and JavaScript.

Source : Browserstack
Selenium 4 brings an easy way of locating elements with the inclusion of relative locators. This means testers can now locate specific web elements using intuitive terms that are often used by users like:
 
* To left of
* To right of
* Above
* Below

The introduction of this new method in Selenium 4 helps locate web elements based on the visual location relative to other DOM elements.
There are several instances in test automation wherein one might need to open a particular link in a new tab or window to perform certain actions. To achieve this in Selenium 3, QAs had to create a new driver object and then perform the switch operation using the WindowHandle method to perform subsequent steps.
 
This is set to change in Selenium 4 as it comes with a new API – newWindow that allows users to create and switch to a new window/tab without creating a new WebDriver object.
 
Sample code snippet to open a new window
driver.get("https://www.google.com/");
// Opens a new window and switches to new window
driver.switchTo().newWindow(WindowType.WINDOW);

// Opens Free Time Learn homepage in the newly opened window
driver.navigate().to("https://www.freetimelearning.com/");

Sample code snippet to open a new tab within the same window
driver.get("https://www.google.com/");

// Opens a new tab in existing window
driver.switchTo().newWindow(WindowType.TAB);

// Opens Free Time Learn homepage in the newly opened tab
driver.navigate().to("https://www.freetimelearning.com/");
Actions class in Selenium is primarily used to simulate input actions from mouse and keyboard on specific web elements (For eg: Left click, Right click, Double click, etc)
 
In Selenium 4, several new methods have been added to the Actions class:
 
click(WebElement) : This method is added to Actions class to replace the moveToElement(onElement).click(). It is used to click on a certain web element.
 
clickAndHold(WebElement) : This method will replace the moveToElement(onElement).clickAndHold(). It is used to click on an element without releasing the click.
 
contextClick(WebElement) : This method will replace moveToElement(onElement).contextClick(). It will perform the right click operation.
 
doubleClick(WebElement) : This method is added to replace moveToElement(element).doubleClick(). It will perform a double click on an element.
 
release() : This method (user for releasing the pressed mouse button) was initially a part of org.openqa.selenium.interactions.ButtonReleaseAction class. Now with the updated version of Selenium, it has been moved to Actions class.
Selenium v1.0 :
* Version 1.0 was the initial release of Selenium.
* It included three tools: Selenium IDE, Selenium RC, and Selenium Grid.

Selenium v2.0:
* Selenium WebDriver was introduced replacing Selenium RC in version "2.0".
* With the onset of WebDriver, RC got deprecated and moved to the legacy package.

Selenium v3 :
* The latest release Selenium 3 has new added features and functionalities.
* It includes Selenium IDE, Selenium WebDriver, and Selenium Grid.
Selenium commands, also known as "Selenese" are the set of commands used in Selenium that run your tests. For example, command - open (URL); launches the desired URL in the specified browser and it accept both relative and absolute URLs.
 
A sequence of Selenium commands (Selenese) together is known as a test script.
Selenium supports Regression testing and Functional testing. 
 
Regression testing : It is a full or partial selection of already executed test cases that are re-executed to ensure existing functionalities work fine.
 
The steps involved are : 
 
Re-testing : All tests in the existing test suite are executed. It proves to be very expensive and time-consuming.
Regression test selection : Tests are classified as feature tests, integration tests,  and the end to end tests. In this step, some of the tests are selected.
Prioritization of test cases : The selected test cases are prioritized based on business impact and critical functionalities.

Functional testing : Functional Testing involves the verification of every function of the application with the required specification. 
 
The following are the steps involved :
 
* Identify test input
* Compute test outcome
* Execute test

Compare the test outcome with the actual outcome 
Selenium 2.0 is a tool that makes the development of automated tests for web applications easier. It represents the merger of the original Selenium project with the WebDriver project. Selenium RC got deprecated since the merge, however, was used for backward compatibility.
 
Selenium 3.0 is the extended version of Selenium 2.0. It is inherently backward compatible and does not involve Selenium RC. The new version came along with several bug fixes and increased stability. 
In Selenium, web elements are identified and located with the help of Locators. Locators specify a target location which uniquely defines the web element in the context of a web application. 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
The list of WebDriver API's which are used to automate browser include :
 
* AndroidDriver
* ChromeDriver
* EventFiringWebDriver
* FirefoxDriver
* HtmlUnitDriver
* InternetExplorerDriver
* iPhoneDriver
* iPhoneSimulatorDriver
* RemoteWebDriver
Yes, Selenium provides good support to launch web browsers like Google Chrome, Mozilla Firefox, Internet Explorer, etc.
 
The following commands can be used to launch web browsers using Selenium :
 
* WebDriver driver = new FirefoxDriver();
* WebDriver driver = new ChromeDriver();
* WebDriver driver = new InternetExplorerDriver();
The language used for writing test scripts in Selenium IDE is called Selenese. It is a set of commands used to test your web application or system. Selenium commands could be divided into 3 major categories:
 
Actions : These are the commands interacting directly with web applications.

Accessors : These are the commands which allow users to store values to a user-defined variable.

Assertions : They enable a comparison of the current state of the application with its expected state.
Assert : Assert command checks if the given condition is true or false. If the condition is true, the program control will execute the next phase of testing, and if the condition is false, execution will stop, and nothing will be executed.
 
Verify : Verify command also checks if the given condition is true or false. It doesn't halt program execution, i.e., any failure during verification would not stop the execution, and all the test phases would be executed.
XPath is also defined as XML Path. It is a language used to query XML documents. It is an important approach to locate elements in Selenium. XPath consists of a path expression along with some conditions. Here, we can easily write XPath script/query to locate any element in the webpage.

It is developed to allow the navigation of XML documents. The key factors that it considered while navigating are selecting individual elements, attributes, or some other part of an XML document for specific processing. It also produces reliable locators. Some other points about XPath are as follows.
 
* XPath is a language used for locating nodes in XML documents.
* XPath can be used as a substitute when you don't have a suitable id or name attribute for the element you want to locate.
* XPath provides locating strategies like :
* XPath Absolute
* XPath Attributes
XPath Absolute : XPath Absolute enables users to mention the complete XPath location from the root HTML tag to the specific elements.

Syntax : //html/body/tag1[index]/tag2[index]/.../tagN[index]
Example : //html/body/div[2]/div/div[2]/div/div/div/fieldset/form/div[1]/input[1]


XPath Attributes :
XPath Attributes is always recommended when you don't have a suitable id or name attribute for the element you want to locate.

Syntax : //htmltag[@attribute1='value1' and @attribute2='value2']
Example : //input[@id='passwd' and @placeholder='password']
Single Slash "/" : Single slash is used to create XPath with absolute path.
 
Double Slash "//" : Double slash is used to create XPath with the relative path.
"type" command is used to type keyboard key values into the text box of software web application. It can also be used for selecting values of combo box whereas "typeAndWait" command is used when your typing is completed and software web page start reloading. This command will wait for software application page to reload. If there is no page reload event on typing, you have to use a simple "type" command.
findElement() findElements()
The first web element that matches the locator is returned. It gives you a list of all the web items that match the locator.
If there are no matching web elements, a NoSuchElementException is produced. If there are no matching elements, an empty list is returned.
Syntax − WebElement button = webdriver.findElement(By.name("<<Name value>>")); Syntax − List<WebElement> buttons = webdriver.findElements(By.name("<<Name value>>"));
Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes, etc) it needs to operate on. Locators specify the area of action.
 
Locator by ID : It takes a string parameter which is a value of the ID attribute which returns the object to findElement() method.
 
  driver.findElement(By.id(“user”));
 
Locator by the link : If your targeted element is a link text then you can use the by.linkText locator to locate that element.
 
  driver.findElement(By.linkText(“Today’s deals”)).click();
 
Locator by Partial link : The target link can be located using a portion of text in a link text element.
 
  driver.findElement(By.linkText(“Service”)).click();
 
Locator by Name : The first element with the name attribute value matching the location will be returned.
 
  driver.findElement(By.name(“books”).click());
 
Locator by TagName : Locates all the elements with the matching tag name
 
  driver.findElement(By.tagName(“button”).click());
 
Locator by classname : This finds elements based on the value of the CLASS attribute. If an element has many classes then this will match against each of them. 
 
  driver.findElement(By.className(“inputtext”));
 
Locator by XPath : It takes a parameter of String which is a XPATHEXPRESSION and it returns an object to findElement() method.
 
  driver.findElement(By.xpath(“//span[contains(text(),’an account’)]”)).getText();
 
Locator by CSS Selector : Locates elements based on the driver’s underlying CSS selector engine.
 
  driver.findElement(By.cssSelector(“input#email”)).sendKeys(“myemail@email.com”);
Implicit wait : Implicit wait commands Selenium to wait for a certain amount of time before throwing a “No such element” exception.
 
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);


Explicit wait : Explicit wait is used to tell the Web Driver to wait for certain conditions before throwing an "ElementNotVisibleException" exception.
 
WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut);


Fluent wait : It is used to tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an "ElementNotVisibleException" exception.
 
Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);
The main disadvantage of implicit wait is that it slows down test performance.
 
Another disadvantage of implicit wait is :
 
Suppose, you set the waiting limit to be 10 seconds, and the elements appear in the DOM in 11 seconds, your tests will be failed because you told it to wait a maximum of 10 seconds.
Following is the major difference between both the commands :
 
driver.close() command closes the currently active window on which the user is working or the window being currently accessed by the web driver.

driver.quit() command, unlike the driver.close() command it closes all the windows opened by the program and hence should be used with care.

Both the commands don’t take any parameter and don’t return any value either.
Selenium has the support of majorly 4 navigation commands :
 
navigate().back() : This command is used for taking the user to the last webpage of the browser history.

navigate().forward() : This command is used for taking the user to the next web page of the browser history.

navigate().refresh() : This command is used for reloading the web components of a webpage by refreshing it.

navigate().to() : This command is used for navigating to a particular URL in a new web browser. It takes the URL to be migrated to, as a parameter.
Following are the different types of frameworks:
 
* Behavior-Driven Development Framework : This type of framework provides a readable and easily understandable format to Business Analysts, Developers, Testers, etc.

* Data-Driven Testing Framework : This type of framework helps separate test data from the test-script logic by storing test data in some external database in the form of key-value pairs. These keys can be used for accessing as well as populating data into the test scripts.

* Keyword-Driven Testing Framework : This type of framework is an extension of the data-driven testing framework. In addition to separating test data and the test-script logic, it also separates a part of the test script code by storing it in an external data file.

* Library Architecture Testing Framework : This type of framework groups common steps into functions under a library and calls these functions as and when required.

* Module-Based Testing Framework : This type of framework divides each test application into several isolated and logical modules, with each module having its distinct test script.

* Hybrid Testing Framework : This type of framework is a combination of the above-mentioned frameworks leveraging all their good features.

Robot Framework is a modular open-source automation framework that can interact with 3rd party libraries and functions. To execute a web testing library such as Selenium, a test automation runner or an automation wrapper is required, which is provided to it in the form of Robot Framework. Other popular test runners to serve the same purpose are MSTest, TestNG, Nunit, Junit, etc.
Feature Selenium IDE Selenium RC WebDriver
Browser Compatibility Selenium IDE comes as a Firefox plugin, thus it supports only Firefox Selenium RC supports a varied range of versions of Mozilla Firefox, Google Chrome, Internet Explorer and Opera. WebDriver supports a varied range of versions of Mozilla Firefox, Google Chrome, Internet Explorer and Opera.
Also supports HtmlUnitDriver which is a GUI less or headless browser.
Record and Playback Selenium IDE supports record and playback feature Selenium RC doesn't supports record and playback feature. WebDriver doesn't support record and playback feature
Server Requirement Selenium IDE doesn't require any server to be started before executing the test scripts Selenium RC requires server to be started before executing the test scripts. WebDriver doesn't require any server to be started before executing the test scripts
Architecture Selenium IDE is a Javascript based framework Selenium RC is a JavaScript based Framework. WebDriver uses the browser's native compatibility to automation
Object Oriented Selenium IDE is not an object oriented tool Selenium RC is semi object oriented tool. WebDriver is a purely object oriented tool
Dynamic Finders
(for locating web elements on a webpage)
Selenium IDE doesn't support dynamic finders Selenium RC doesn't support dynamic finders. WebDriver supports dynamic finders
Handling Alerts, Navigations, Dropdowns Selenium IDE doesn't explicitly provides aids to handle alerts, navigations, dropdowns Selenium RC doesn't explicitly provides aids to handle alerts, navigations, dropdowns. WebDriver offers a wide range of utilities and classes that helps in handling alerts, navigations, and dropdowns efficiently and effectively.
WAP (iPhone/Android) Testing Selenium IDE doesn't support testing of iPhone/Andriod applications Selenium RC doesn't support testing of iPhone/Android applications. WebDriver is designed in a way to efficiently support testing of iPhone/Android applications. The tool comes with a large range of drivers for WAP based testing.
For example, AndroidDriver, iPhoneDriver
Listener Support Selenium IDE doesn't support listeners Selenium RC doesn't support listeners. WebDriver supports the implementation of Listeners
Speed Selenium IDE is fast as it is plugged in with the web-browser that launches the test. Thus, the IDE and browser communicates directly Selenium RC is slower than WebDriver as it doesn't communicates directly with the browser; rather it sends selenese commands over to Selenium Core which in turn communicates with the browser. WebDriver communicates directly with the web browsers. Thus making it much faster.
The user can use sendKeys(“String to be entered”) to enter the string in the textbox.
 
Syntax :
WebElement username = drv.findElement(By.id(“Email”));
// entering username
username.sendKeys(“sth”);
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.
 
* isDisplayed()
* isSelected()
* isEnabled()

Syntax :
 
isDisplayed()boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
 
isSelected()boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isSelected();
 
isEnabled() : boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
The value in the dropdown can be selected using WebDriver’s Select class.
 
Syntax :
 
selectByValue :
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(“greenvalue”);
 
selectByVisibleText :
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);
 
selectByIndex :
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);
getwindowhandles() : This is used to get the address of all the open browsers and returns the data type of Set<String>.
 
getwindowhandle() : This is used to get the address of the current browser window where it’s focused on and returns the data type of String.
These methods will delay the speed of the execution. 
 
Thread.sleep() : The current thread will stop for a specified period of time. It only waits once when the command is given. It takes only a single argument that is Integer format.
 
set sleep() : This command will stop the execution for every selenium command. This command is used only for demonstration purposes and also for a slow web application.
Advantages or Benefits of RC include,
 
* Data can be read or write to or from .xlsx, .csv, .txt etc.,
* Dynamic objects and Ajax based UI elements can be handled.
* Conditional statements and Iterations functionalities can be used to improve and enhance performance and flexibility.
* Support for any programming languages and Operating systems.
* Selenium RC can be used on any browser which is enabled with Java script.
Break points : The flow of execution is stopped using the breakpoints. By doing this we can verify that the code is working in an expected manner or not.
 
Start points : The point from where the execution should begin is determined by the start points. When you want to run a test script from the middle of the code or a breakpoint, we use these.
As we already know that Selenium is used only to automate web applications. But if we want to handle or manage or maintain the GUI, HTML pop-ups then, we need the use of AutoIT.
Feature Selenium Quick Test Professional (QTP)
Browser Compatibility Almost all popular browsers are supported. Firefox, Chrome, Safari, Internet Explorer, Edge, etc. This supports only Chrome, Firefox, and Internet explorer. Also, it supports only the Windows operating system.
Distribution Distributed as open-source and it is freely available. Distributed as a licensed tool and is commercialized.
Application Under Test (AUT) Web-based applications are only supported in this kind of automated testing. This provides support for both webs- based as well as windows applications for automated testing.
Object Repository The separate entity in Selenium is used to create the object repository. Automatic creation of the Object repository happens and is maintained too
Language Support Multiple Programming languages like Java, Python, Perl, Ruby, C#, etc., are supported by this Selenium. Only VBScript language is supported by this QTP.
Vendor Support As we already know that Selenium is a free tool, we do not get vendor support in troubleshooting the issues we face. Vendor support is guaranteed for the users using the QTP and they do get quick responses as QTP is commercialized and licensed.
The following are the challenges we face while handling the AJAX calls :
 
* Pause command in Ajax calls is not conventional and reliable in handling. Long pauses do cause the test case execution increases the time of execution. We can use the waitForCondition instead to test the AJAX applications.

* Assessing the risk associated with these applications is difficult.

* Encoding and Serialization in the AJAX applications make it difficult in developing the automation test case scenarios.
Features Selenium HP QTP
TestComplete
License Open Source Required Required
Cost Free High High
Customer support Yes; Open source community Yes Yes
Release Cycles/ Development Sprints Smaller release cycles with immediate feedback Smaller release cycles Agility only
Coding skills Very High Low High
Environment support Windows, Linux, Mac Only Windows Windows only (7, Vista, Server 2008 or later OS)
Language support Language support VB Script VB Script, JS Script, Delphi Script, C++ & C#
Page Object Model is a design pattern for creating an Object Repository for web UI elements. Each web page in the application is required to have it’s own corresponding page class. The page class is thus responsible for finding the WebElements in that page and then perform operations on those WebElements.
 
The advantages of using POM are :
 
* Allows us to separate operations and flows in the UI from Verification – improves code readability
* Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository
* Reusability of code
We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are in the table below :

Method Description
clickAndHold() Clicks (without releasing) the current mouse location.
dragAndDrop() Performs click-and-hold at the location of the source element, moves.
source, target() Moves to the location of the target element, then releases the mouse.
Selenium does not support handling pop-ups. Alert is used to display a warning message. It is a pop-up window that comes up on the screen.
 
A few methods using which this can be achieved :
 
Void dismiss() : This method is called when the ‘Cancel’ button is clicked in the alert box.

Void accept() : This method is called when you click on the ‘OK’ button of the alert.

String getText() : This method is called to capture the alert message.

Void sendKeys(String stringToSed) : This is called when you want to send some data to alert box.
This Robot class provides control over the mouse and keyboard devices.
 
The methods include :
 
KeyPress() : This method is called when you want to press any key.

KeyRelease() : This method is used to release the pressed key on the keyboard.

MouseMove() : This method is called when you want to move the mouse pointer in the X and Y co-ordinates.

MousePress() : This is used to press the left button of the mouse.

MouseMove() : This method helps in releasing the pressed button of the mouse.
When we generally use ALT/SHIFT/CONTROL keys, we hold onto those keys and click other buttons to achieve the special functionality. So it is not enough just to specify keys.ALT or keys.SHIFT or keys.CONTROL functions.
 
For the purpose of holding onto these keys while subsequent keys are pressed, we need to define two more methods: keyDown(modifier_key) and keyUp(modifier_key)
 
Parameters : Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Purpose : Performs a modifier key press and does not release the modifier key. Subsequent interactions may assume it’s kept pressed.
 
Parameters : Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Purpose : Performs a key release.

Hence with a combination of these two methods, we can capture the special function of a particular key.
public static void main(String[] args) 
{
String baseUrl = &ldquo;https://www.facebook.com&rdquo;;
WebDriver driver = new FirefoxDriver();
 
driver.get("baseUrl");
WebElement txtUserName = driver.findElement(By.id(&ldquo;Email&rdquo;);
 
Actions builder = new Actions(driver);
Action seriesOfActions = builder
 .moveToElement(txtUerName)
 .click()
 .keyDown(txtUserName, Keys.SHIFT)
 .sendKeys(txtUserName, &ldquo;hello&rdquo;)
 .keyUp(txtUserName, Keys.SHIFT)
 .doubleClick(txtUserName);
 .contextClick();
 .build();
seriesOfActions.perform();
}
Parameterization is the technique of defining values in testng.xml file and sending them as parameters to the test class. This technique is especially useful when we need to pass multiple login credentials of various test environments. Take a look at the code below, in which “myName” is annotated as a parameter.
public class ParameterizedTest1{
 @Test
 @Parameters("myName")
 public void parameterTest(String myName) {
 System.out.println("Parameterized value is : " + myName);
 }
}
 
To pass parameters using testng.xml file, we need to use ‘parameters’ tag. Look at the below code for example :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 <suite name=&rdquo;CustomSuite">
  <test name=&rdquo;CustomTest&rdquo;> 
   <parameter name="myName" value=&rdquo;John"/>
    <classes>
     <class name="ParameterizedTest1" />
    </classes> 
  </test>
</suite>
While working with Selenium, we need session handling. This is because, during test execution, Selenium WebDriver has to interact with the browser all the time to execute the given commands. It is also possible that, before the current execution completes, someone else starts the execution of another script in the same machine and in the same type of browser. So, to avoid such a situation, we need session handling.
In Selenium IDE, we use Selenese Verify and Assert Commands as Verification points.

In Selenium WebDriver, there is no built-in features for verification points. It totally depends on our coding style. some of the Verification points are :
 
* To check for page title
* To check for certain text
* To check for certain element (text box, button, drop down, etc.)
The advantages of Using Git Hub for Selenium are :
 
* Multiple people when they work on the same project they can update project details and inform other team members simultaneously.

* Jenkins can help you to build the project from the remote repository regularly. This helps you to keep track of failed builds.
# JXL jar POI jar
1 JXL supports “.xls” format i.e. binary based format. JXL doesn’t support Excel 2007 and “.xlsx” format i.e. XML based format POI jar supports all of these formats
2 JXL API was last updated in the year 2009 POI is regularly updated and released
3 The JXL documentation is not as comprehensive as that of POI POI has a well prepared and highly comprehensive documentation
4 JXL API doesn’t support rich text formatting POI API supports rich text formatting
5 JXL API is faster than POI API POI API is slower than JXL API
Links or URLs that are not reachable are known as broken links. They may be unavailable or inoperable due to a server issue. A URL's status will always be 2xx, indicating that it is legitimate. There are a variety of HTTP status codes, each with its own set of functions. HTTP status 4xx and 5xx indicate an invalid request. The 4xx class of status codes is used for client-side errors, while the 5xx class is used for server response errors.

You should always check for broken links on your site to ensure that the user does not end up on an error page. If the rules aren't updated appropriately, or the requested resources aren't available on the server, the error will occur. Manual link checking is a time-consuming task because each web page may have a huge number of links, and the process must be performed for each page. 
 
To find broken links in Selenium, follow the instructions below.
 
* Using the <a> (anchor) tag, collect all of the links on a web page.
* For each link, send an HTTP request.
* Make that the HTTP response code is correct.
* Based on the HTTP response code, determine whether the link is genuine or not.
* Repeat the procedure for all of the links that were captured in the first step.

package SeleniumPackage;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class BrokenLinks {
   
   public static void main(String[] args) {
       
       String pageURL = "http://www.freetimelearnig.com";
       String url = "";
       HttpURLConnection huc = null;
       int responseCode = 200;
       System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\selenium\\chromedriver_win32\\chromedriver.exe");
       ChromeOptions options = new ChromeOptions();
       options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors", "--silent");
       WebDriver driver = new ChromeDriver(options);//Creating an instance of the WebDriver class
       
       driver.manage().window().maximize();
       
       driver.get(pageURL);
       
       List<WebElement> links = driver.findElements(By.tagName("a")); // getting hold of all the elements having the anchor tag
       
       Iterator<WebElement> it = links.iterator();
       // Iterating over the obtained list of elements and checking them one by one
       while(it.hasNext()){
           
           url = it.next().getAttribute("href");
           
           System.out.println(url);
       
           if(url == null || url.isEmpty()){
               System.out.println("The linked element has invalid href url.");
               continue;
           }
           
           if(!url.startsWith(pageURL)){
               System.out.println("URL belongs to another domain, skipping it.");
               continue;
           }
           
           try {
               huc = (HttpURLConnection)(new URL(url).openConnection());
               
               huc.setRequestMethod("HEAD");
               
               huc.connect(); // connecting to the url
               
               responseCode = huc.getResponseCode(); // reading the response code on firing the url
               
               if(responseCode >= 400){
                   System.out.println(url+" is a broken link");
               }
               else{
                   System.out.println(url+" is a valid link");
               }
                   
           } catch (MalformedURLException e) {
               e.printStackTrace();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
       
       driver.quit();
   }
}​
public class ChromeBrowserLaunchDemo {  
  
public static void main(String[] args) {  
  
//Creating a driver object referencing WebDriver interface  
WebDriver driver;  
  
//Setting the webdriver.chrome.driver property to its executable's location  
System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");  
      
//Instantiating driver object  
driver = newChromeDriver();  
  
//Using get() method to open a webpage  
driver.get("http://freetimelearning.com");  
  
//Closing the browser  
driver.quit();  
  
    }  
}