Currently Browsing

Posts Tagged ‘ Selenium WebDriver ’

How to check presence of an element when it disappears in less than 500ms

It can happen that the element you want to check only appears for a fraction of a second. This can produce false failures when the element appears in between the standard 500ms when WebDriver checks the wait condition. What you can do is to set up a FluentWait object with a specific polling time. It works almost the same as other kinds of wait functions in WebDriver.

The code is the following:

	Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
				.withTimeout(20, java.util.concurrent.TimeUnit.SECONDS)
				.pollingEvery(200, java.util.concurrent.TimeUnit.MILLISECONDS)
		Function<WebDriver, WebElement> function = new Function<WebDriver, WebElement>() {
			public WebElement apply(WebDriver driver) {
				return driver.findElement(exportSnackbarCss);

Running webdriver code in JMeter

With the improvements in technology more and more of the business logic gets executed on the client side and it’s not easy to get a clear picture of the perceivable performance by using pure JMeter tests only.
To extend these measurements JMeter-Webdriver plugin in JMeter can be handy to run WebDriver tests using actual browsers and to get client side execution statistics.

In the following section I will demonstrate how to configure and run a simple WebDriver test in JMeter.

First you have to download the plugin from the JMeter plugin page and then copy the library files into JMeter installation folder.

From now on when you start up JMeter you should have the extra Config Element and Sampler components visible on the tool list and they are ready to use

BlazeMeter – Work with Selenium Webdriver

It was a long time we wrote about the BlazeMeter and during this time it comes more reliable, easy to use and there are also some new, great tools (Here you can find our latest post about BlazeMeter: Previous post about loadtesting with BlazeMeter).
Maybe the most important feature is that now you can use Selenium Webdriver to describe your test scenario. There are two ways of creating Selenium Webdriver test on BlazeMeter. You can write your own Selenium Webdriver script or you can record it. Unfortunately recording function was not published yet, so we will explain it in one future post (the link will be placed here).

How to count number of images available on a web page then download them using selenium webdriver?

The simplest way to gather the images from a website is to find them by tagName.
First we create a WebElement list with the elements which tagName is ”img”.
Then we check the elements to be sure that they are displayed.
If they are displayed then we get their names and sources.
To download them we use the “” function.
It is very simple, we just need to add the URL and the file path to it.
In the end we write out the number of displayed elements.

Here is to full code:

Browserstack integration with junit and webdriver

The purpose of this article is to show how easy is to integrate webdriver with architectures on the cloud, in this case with Browserstack.

For every new tool the first thing to do is to check out and examine the documentation.
The basic steps are very well documented, the examples and the thorough explanations give good impressions. I was able to make a simple test run on their architecture in a couple of minutes.
There is a section with an idea for parallelization, it is worth checking out, as you can get some ideas on improving your testbase. Link to their site is

Parameterized JUnit tests with Selenium WebDriver

With JUnit 4 we’re able to Parameterize the tests. Parameterized tests allow developers to run the same tests over and over again using different values.

Now we introduce the way to use the parameterized JUnit tests with Selenium WebDriver.

Here is the sample code, which opens the Google search page, searches three different phrases and checks the results.

Basic HTTP authentication and Webdriver

I encountered an interesting problem last week.
I had to make an automated test scripts on a test site which was protected by Basic HTTP Authentication.
I’ll assume that everybody knows how Basic HTTP Authentication works and will just focus on the solution:

 WebDriver driver = new ChromeDriver();

Of course you should change the username, password and URL strings to your data .
To pass the basic http authentication in firefox, you have to set a browser preference during the driver creation.

 FirefoxProfile profile = new FirefoxProfile();
 profile.SetPreference("network.http.phishy-userpass-length", 255);
 driver = new FirefoxDriver(profile);

The added setting will disable the anti-phishing dialog box.

How to use TestNG with Selenium WebDriver

(The precondition for this tutorial that the Selenium WebDriver is already installed.)
Firstly go to TestNG website’s download page, and follow the instructions to install the TestNG plugin to Eclipse. (

After the TestNG was installed, create a new java class file (without main method).

Create the setUp() function. To this function you can put that the WebDriver use for example the Firefox browser, and for example that the driver get the desired webpage.

This function will start before the test. To ensure that, before the setUp() function need to put @BeforeClass annotation.

@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.

If you use only one test in the java file then you can use the @BeforeTest annotation too.

@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.

Webdriver – XPath and CSS selector performance tip

There are cases when using XPath has some advantages over CSS selectors.
For example if there is a site where we can select an item only by text because the other type of locators are not clear(id’s and classes are generated and they are used in multiple places).

What can we do in this situation?

  1. Use a CSS locator to select multiple elements and then call the getText() function and compare the results with the selected string
    This is a working solution, but Webdriver calls are expensive and it can really slow down test runs in IE8 and IE9 browsers.
  2. Use the XPath’s contains function to select the element by its text value
    span[contains(text(),’Text to search for’)]
Short background story:

To solve our initial problem using CSS we have been forced to use the getText() function to be able to compare the text and get the appropriate element.
When we came up with the 2. solution the overall run time of the tests have been reduced and the test runs became more stable in IE8 and IE9.

How to integrate a JUnit4 – Webdriver test into JMeter

JMeter is an open source load testing tool, with many capabilities. One of the many interesting things which can be done is to integrate a webdriver test into a JMeter test suite.

Before start make sure that Java and JMeter properly installed, and the webdriver libraries are downloaded. You can download them from the following links:

The following step is to create a new project in Eclipse with a webdriver test. To keep it simple the test just hits the page, and will check its title.

To create a project:
– Click File -> New- > Java Project

New Java Project

New Java Project

– Enter project name -> click Finish

New Java Project Name

New Java Project Name