Bob Meliev is a Contributing Writer to the BlazeMeter blog

Become a JMeter and Continuous Testing Pro

Start Learning

Test Your Website Performance NOW! |

arrowPlease enter a URL with http(s)
Apr 02 2019

Using Selenium with JMeter's WebDriver Sampler

How to Use Selenium with JMeter's Webdriver Sampler


To use Selenium Webdriver with JMeter, simply install "Webdriver Set" plugins. The WebDriver sampler is useful for testing the performance of AJAX, GWT-based Web applications, and simulated user actions.


Install the Webdriver using the JMeter Plugins Manager.


Write your WebDriver script as usual, then add "Thread Group" to your "Test Plan."


WebDriver plugins installed open Jmeter - Firefox Driver Config.



Add Config Element -> HTTP Cookie Manager, Config Element -> jp@gc - Firefox Driver Config, Sampler -> jp@gc - Web Driver Sampler, Listener -> View Results Tree.


The result is as follows:


add "Thread Group" to your "Test Plan"

You do not need to configure two config elements – you may omit that step. Open the "Web Driver Sampler" and add this code:


var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes
var support_ui = JavaImporter(; //WebDriver classes
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);

WDS.sampleResult.sampleStart(); //captures sampler's start time
WDS.sampleResult.getLatency();"Sample started");

WDS.browser.get(''); //opens website specified in ''"Sample ended - navigated to");

var searchField = WDS.browser.findElement('search_form_input_homepage')); //saves search field into searchField; //clicks search field
searchField.sendKeys(['blazemeter']); //types word "blazemeter" in field"Searched for BlazeMeter");

var button = WDS.browser.findElement('search_button_homepage')); //Find Search button; //Click Search Button"Clicked on the search button");

var link = WDS.browser.findElement(pkg.By.cssSelector('#r1-0 > div > h2 > a.result__a > b')); //also saves selector as variable but uses CSS.; //Click the search result's Link



(Don't worry if the entire code doesn’t seem clear yet. We'll revisit it below).


Now, try to start your test. Whatever you do, DO NOT change the "Thread Group" values. They must all be set to 1.


 "Thread Group" values must be 1!


You should see the new Firefox window that will open the website. Search for “BlazeMeter.” After the test has started, open View Results Tree to confirm there are no errors. If the Response Code is “200” and the Response Message is “OK,” the test was run successful. If not, check the WebDriver script for errors. 


Code Review


Our code starts with the import Java packages “org.openqa.selenium” and “” that allow you to use the WebDriver classes.  


Here is a handy list of WebDriver’s packages.


If you want to use any of the packages, import them with JavaImporter:


var action = JavaImporter(org.openqa.selenium.PACKAGENAME.CLASSNAME)


WDS.sampleResult.sampleStart() and WDS.sampleResult.sampleEnd() captures the sampler’s time and tracks it. You can remove them. The script will still work, but you can’t get load time:


Load Time-JMeter WebDriver Sampler


  • WDS.browser.get('') - Opens the website


  • var searchField = WDS.browser.findElement('search_form_input_homepage')) - Saves the search field into searchField variable.


  • - Clicks the search field.


  • searchField.sendKeys(['blazemeter']) - Types “blazemeter” in field


  • var link = WDS.browser.findElement(pkg.By.ByCssSelector('#r1-0 > div > h2 > a.result__a > b')) - Saves selector as variable but uses CSS.


  • + ' has logged an entry') - Logs a message.


How to Use Selectors


To simplify the use of selectors, install the Selenium IDE add-on. Selenium IDE is a Firefox add-on with a recording option for actions in the browser. To get similar selectors, download and install the add-on. (Be sure to download the .xpi file.)


Open Duck Duck Go and Selenium IDE. Set the Selenium IDE’s base URL Type “blazemeter” and click Search. If you open Selenium IDE, you see the captured actions and selectors.



Webdriver JMeter Selenium Blog


All captured data can be manually converted to the WebDriver format(see below).


captured data can be manually converted to WebDriver format.


Start the Test Run on BlazeMeter


To launch the WebDriver test in the cloud with more concurrent users on BlazeMeter, use Firefox, which is the only currently supported browser for use with WebDriver. Create a new test and upload your JMX file to run it.


Before uploading your JMeter script, it’s best to remove/disable View Results Tree, which can slow test performance. After a few minutes, reports will generate. We launched the test with 40 concurrent users, as noted in the response time (*see the Monitoring tab).


blazemeter, selenium webdriver, reporting


Although we launched the test with only 40 users, the CPU is fully utilized from the outset. This is precisely why each sampler starts one browser. Be sure to take this into account when writing tests.


BlazeMeter Recommends


When using the WebDriver plugin, in order to perform better load testing, assemble the Selenium tests with JMeter tests. The number of WebDriver samplers should be fewer than the number of JMeter samplers. If you need any values from websites through Ajax, you can use WebDriver with the Once Only Controller to avoid continual/duplicate browser launches.


You can also use Taurus with its native Selenium executions, as a way to leverage existing functional tests written in Selenium.


Read more about Continuous Testing in our White Paper "Continuous Testing in Practice"

arrowPlease enter a URL with http(s)

Interested in writing for our Blog?Send us a pitch!