Home > Software design >  How to extract variable from jmeter selenium webdriver
How to extract variable from jmeter selenium webdriver

Time:04-23

I have a token thats being returned in the body.

WDS.browser.findElement(org.openqa.selenium.By.xpath("//*[contains(@name,'RequestVerificationToken')]")).getText();

This is the token I'm trying to extract:

enter image description here

Now what im trying to do is to pass that variable out of the selenium webdriver to the rest of the threads.

Usually when im working with normal pages I go for regular expression extractor as a post processor and set to a variable then correlate it but Im not sure where to go here.

How do I make it a global variable in JS?

CodePudding user response:

You can consider the complete value of the name attribute. Additionally, the token is actually the value attribute, so you have to use getAttribute("value") instead as follows:

WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[@name='__RequestVerificationToken']")).getAttribute("value");

CodePudding user response:

The element you want to interact with doesn't have text, what you need is value attribute so you need to amend your code as:

var token = WDS.browser.findElement(org.openqa.selenium.By.xpath("//*[contains(@name,'RequestVerificationToken')]")).getAttribute('value')

If you want to share this token with all threads in this or other Thread Groups you can save it into a JMeter Property like:

WDS.props.put('token', token)

so in other WebDriver Samplers instances you will be able to access it as:

var token = WDS.props.get('token')

and in other JMeter test elements it will be possible to use __P() function like:

${__P(token,)}

More information: The WebDriver Sampler: Your Top 10 Questions Answered

  • Related