Selenium Tutorials

If you are a beginner, please Proceed here to start from the beginning.

StaleElementReference Exceptions in Selenium Webdriver

This Exception occurs when driver is trying to perform action on the element which is no longer exists or not valid.

WebElement ele = driver.findElement(By.id("sample"));
// Before clicking some thing happened and DOM has changed due to page refresh, or element is removed and re-added
ele.click();

Now at this point, the element which you're clicking is no longer valid.

so it throws up its hands and gives control to user, who as the test/app author should know exactly what may or may not happen.

Mouse Hover Actions in Selenium Webdriver

In order to perform a 'mouse hover' action, we need to chain all of the actions that we want to achieve in one go. So move to the element that which has sub elements and click on the child item. It should the same way what we do normally to click on a sub menu item.

With the actions object you should first move the menu title, and then move to the sub menu item and click it.

First we need to create new action builder instance by passing the webdriver instance, then.

Below is the sample code to perform Mouse hover action

Example 1:

Importance of Automation Testing

Companies not only want to test software adequately, but also as quickly and thoroughly as possible. To accomplish this goal, organizations are turning to automated testing.

To increase the test coverage

Reduces the need for manual testing and discovers defects manual testing cannot expose and also manual testing is error prone and a time consuming process.

Running the tests again and again gives us the confidence that the new work we added to the system did not break the code that used to work and also to make sure that the changes we introduced are working.

Why Automation Testing is required?

Automated software testing is the best way to increase the effectiveness, efficiency and coverage of your software testing. Every software development group tests its products, yet delivered software always has defects.

Test engineers strive to catch them before the product is released but they always creep in and they often reappear, even with the best manual testing processes.

Defining Firefox Profile preferences using Selenium Webdriver

Some times, you may need to update the preferences within Firefox. We can do this by instantiating a Firefox Profile object and then update the settings.

We will then need to pass this object into FirefoxDriver which will load the profile with your defined settings.

You can check them using command "about:config" in the borwser. It will display a warning message and then asks you to proceed if required. Becarefull when doing any changes.

How to handle javascript alerts, confirmation and prompts?

Generally JavaScript popups are generated by web application and hence they can be easily controlled by the browser.

Webdriver offers the ability to cope with javascript alerts using Alerts APIClick here to view Alert API Details

// Get a handle to the open alert, prompt or confirmation
Alert alert = driver.switchTo().alert();

Alert is an interface. There below are the methods that are used

//Will Click on OK button.
alert.accept();

Working with Frames in Selenium Webdriver

What is iFrame? An iFrame (Inline Frame) is an HTML document embedded inside the current HTML document on a website. iFrame HTML element is used to insert content from another source, such as an advertisement, into a Web page. A Web designer can change an iFrame's content without making them reload the complete website. A website can have multiple frames on a single page. And a frame can also have inner frames (Frame in side a Frame)

Firefox Not Connected Exception in Selenium

Scripts that worked earlier may be till yesterday are NOW not working because of Firefox browser upgraded to new version.

Most of them have faced the similar problem when the browser has updated to version . This is the first issue user notices when there is an update in the firefox browser and may not support selenium with older version of jars.

First we need to check if the selenium has come up with new version. Click here to download the latest version of selenium

CSS selectors for Selenium with example

When we don't have an option to choose Id or Name, we should prefer using CSS locators as the best alternative.
CSS is "Cascading Style Sheets" and it is defined to display HTML in structured and colorful styles are applied to webpage.

Selectors are patterns that match against elements in a tree, and as such form one of several technologies that can be used to select nodes in an XML document. Visit to know more W3.Org Css selectors