# Jmeter's WebDriver Sampler VS. Selenium

Now that Jmeter has a webdriver sampler, is there anything that regular selenium can do to test a UI, that Jmeter still can't?

For example, I use Selenium in Java to do things like getting html attributes of an element element.getAttribute("title");

and waiting for conditions up to a maximum time

Wait<WebDriver> customWait = new FluentWait<WebDriver>(driver)
.withTimeout(15L, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);


switching between windows, and more.

I've seen some example code for the Webdriver sampler here: http://jmeter-plugins.org/wiki/WebDriverSampler/?utm_source=jpgc&utm_medium=link&utm_campaign=WebDriverSampler

But it doesn't show how to accomplish tasks like the above - only how to send keys and click on elements.I can't find any documentation online regarding how to use the Webdriver sample to accomplish tasks like the above and others.

Is it possible to do these using Jmeter's webdriver sampler?

Besides these examples, what are other things you can do in Selenium, which Jmeter's webdriver sampler can't yet do?

In particular:

1. Get data from WebDriver Sampler into JMeter variable:

You can pass data to JMeter via WDS.sampleResult.setResponseHeaders() method (body and message are being overwritten by the WebDriver Sampler). Once you set the headers you can fetch the data via Regular Expression Extractor. If you need to pass multiple variables headers can be split via \n delimiter like

If you need to extract multiple values and more headers, you can use the “\n” delimiter. Here’s an example of how this is used correctly:

WDS.sampleResult.setResponseHeaders('Header_1_Name: Header_1_Value' + '\n' + 'Header_2_Name: Header_2_Value')

2. In order to wait for some element to appear in DOM use the following approach:

var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait=new support_ui.WebDriverWait(WDS.browser, 10)

WDS.sampleResult.sampleStart()
WDS.browser.get('http://example.com')
element.click()
WDS.sampleResult.sampleEnd()

3. To switch between windows refer to the following code snippet

WDS.sampleResult.sampleStart()
WDS.browser.get('http://example.com')
var handles = WDS.browser.getWindowHandles()
var iterator = handles.iterator()
var counter = 1;
while (iterator.hasNext())
{
var handle = iterator.next()
WDS.browser.switchTo().window(handle)
WDS.log.info('Window ' + counter + ' title = ' + WDS.browser.getTitle())
counter++;
}
WDS.sampleResult.sampleEnd()


Hope this helps.

• Answers with only a link are discouraged because if the link moves or vanishes, your answer is no longer useful. Please try to summarize what information can be found at the link – Yamikuronue Sep 22 '14 at 17:22
• Corrected the answer according to your comment, thanks. – Dmitri T Sep 23 '14 at 7:20

Imagine a jackhammer with a Phillips-head screwdriver welded onto the handle. You could, in theory, use this modified jackhammer for screwing things together, but you probably wouldn't want to.

JMeter is a tool for performance testing. Selenium is a tool for functional testing. I talk about the differences between the two kinds of testing here.

Agree with @user246 JMeter is for load testing and recommended to use WebDriver in JMeter paralel with load tests for Ajax applications. But if you run WebDriver sampler in "Once Only Controller" you are fine. Here you can find article about JMeter WebDriver sampler.

• I'm not sure this is relevant to the original question. The article you linked talks about using Selenium with JMeter, not using JMeter instead of Selenium. – Kate Paulk Sep 24 '13 at 11:43
• @KatePaulk Pat Meeker, asked "Is it possible to do these using Jmeter's webdriver sampler?" and link is the answer to his question. – Bobur Meliev Sep 25 '13 at 6:04
• I think everyone would be better served if you extracted the relevant portions of the link (helps to prevent link rot) and then the answer can be evaluated strictly on its content as opposed to outsourcing that content. – corsiKa Sep 29 '14 at 16:07

just my 5 cents - you can use a WebDriverRemote in jmeter, controling it with java||groovy code in JSR223 samples. You just start chromedriver.exe (or what is its equivalent on *nix OS) and then import org.openqa.selenium (the jar must be in ur jmeter classpath) and you get the full power of selenium webdriver integrated in the jmeter scenario. Hope that helps.