How to get the value of a data-amount JMeter
I tried to get the value using a xpath extractor. But I always got an empty string. What am I doing wrong?
//*[#class = 'panel-body']//*[#class='fade-in'][1]/#data-amount
There is a couple of problems with your XPath expression, for instance:
//*[#class = 'panel-body']//*[#class='fade-in'][1]/#data-amount
^ - extra slash ^ - not required
I also don't like * wildcard, however it might be a weird form of your test scenario so let it be.
Being converted to "normal" XPath expression it should look something like:
//*[#class='panel-body']/*/#data-amount
Demo:
It may be simplified to something like:
//div[#data-action='bid_online']/#data-amount
References:
XPath Language Specification
Using the XPath Extractor in JMeter
XPath Tutorial
Related
I have issue with debug sampler not showing regular expression extractor in Jmeter. Kindly refer the tree below:
Here is the information in my regular expression extractor:
There's no regular expression variables shown in debug sampler output:
Can help to see what's the real issue here? FYI I'm scripting using webtours demo website & havent parameterize username and password yet coz i want to make sure my correlation works first. Thanks.
Without seeing the response it's hard to say what is wrong, most probably your Regular Expression Extractor fails somewhere somehow, as per documentation:
Template
The template used to create a string from the matches found. This is an arbitrary string with special elements to refer to groups within the regular expression. The syntax to refer to a group is: '$1$' to refer to group 1, '$2$' to refer to group 2, etc. $0$ refers to whatever the entire expression matches.
so for sure you need to change $1 to $1$
Using regular expressions for parsing HTML is not the best idea, I would recommend consider using CSS Selector Extractor instead, the relevant configuration would be something like
I don't think your PostProcessor placement is correct, it's a Post processor so according to the JMeter test elements execution order it is executed after the sampler and you're trying to use the variable in the same request. So my expectation is that you need to move it under the "Homepage" sampler
Add HTTP Cookie Manager to your Test Plan
I need to extract value from the response body text and need to add that value for another request. I need to write a regular expression to capture the below-mentioned value.
<id>45893943</id>
If you're looking for a regular expression - it would be something like <id>(\d+)</id> where:
d - matches any number
+ - repetition
It might be easier for you to consider Boundary Extractor as it's configuration is more simple and it acts much faster, just provide <id> as the left boundary and </id> as the right boundary and JMeter will extract everything between the boundaries:
And last but not the least, using regular expressions for parsing HTML or XML is not the best idea, you might want to use CSS Selector Extractor or XPath Extractor instead, however we need to see the full response in order to be able to come up with the best solution
Regular Expression -"p_instance" value="(.*?)"
Match count: 1
Match[1][0]="p_instance" value="11917272245034"
Match[1][1]=11917272245034
When added $1$ in template - error is displayed(request is not created)
$1$$1$ is dding duplicate strings in the request.
What should be the template to fetch this value
Just add a Debug Sampler to your Test Plan - this way you will be able to see all the variables generated by the Regular Expression Extractor in the View Results Tree listener. See How to Debug your Apache JMeter Script article for more details.
Going forward when asking for a help with the regular expressions include essential part of the response and indicate which value you are looking for.
Here comes mandatory advice not to use regular expressions for parsing HTML and suggestion to use CSS/JQuery Extractor or XPath Extractor instead.
html code
<span id="nameDomain">gmail.com</span>
How to take the field values in Regular Expression extractor of jmeter
What i have to give
Regular Expression:
Template:
Match No.(0 for Random):
You can check the below example to extract the value.
You need to use ${spanval} in the subsequent requests to access the value you have extracted.
Check this: JMeter - Regular Expression
Extractor
In general using regular expressions to parse HTML isn't a very good idea as regular expressions are very sensitive to markup change and very fragile.
You can use XPath Extractor instead.
Add XPath Extractor as a child of the request which returns that "span" and configure it as follows:
Check Use Tidy box if response is not XHTML-compliant
Reference Name: anything meaningful, i.e. nameDomain
XPath Query: //span[#id='nameDomain']/text()
Refer extracted value as ${nameDomain} where required.
See XPath Tutorial for language reference and Using the XPath Extractor in JMeter for some more details.
If you still want to use Regular Expressions, the relevant Regular Expression will be <span id="nameDomain">(\S+)</span> and Template $1$. Other fields (apart from the "Reference Name" may be left as they are.
The Response data look like following within Script tag
var csrfParam =
"SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD=y2G5Of06jgHbkNdHNleFKiXoBMC62veD";
var securityTokenName = "SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD";
var securityTokenValue = "y2G5Of06jgHbkNdHNleFKiXoBMC62veD";
I'm using regular expression extractor as following:
Reference name : MYREF
Regular Expression : securityTokenName ="(.+?)" securityTokenValue="(.+?)"
Template : $1$$2$
I'm access this variable in next Jmeter request to build the URL:
${MYREF_g1}
${MYREF_g2}
Expecting to get MYREF_g1 =SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD
and MYREF_g2 =y2G5Of06jgHbkNdHNleFKiXoBMC62veD
But THIS is not working .
Any help would appreciated!
It looks like that you're misunderstanding what groups and templates are.
As per Using RegEx (Regular Expression Extractor) with JMeter
Template. The template used to create a string from the matches found.
This is an arbitrary string with special elements to refer to groups
within the regular expression. The syntax to refer to a group is:
'$1$' to refer to group 1, '$2$' to refer to group 2, etc. $0$ refers
to whatever the entire expression matches. So, if you have in response
word “economics” and search for regular expression “(ec)(onomics)” and
apply template $2$$1$ than in output variable you will receive
“onomicsec”.
So your RegEx should look like:
var securityTokenName = "(.+?)"; var securityTokenValue = "(.+?)";
So
securityTokenName will be stored in JMeter Variable MYREF_g1
securityTokenValue will be stored in JMeter Variable MYREF_g2
View Results Tree Listener has built-in RegExp Tester on ResponseData tab. You can also use Debug Sampler to see what variables have been set by your Regular Expression Extractor.
You need multiline regex match. Your regex will look like this
(?s)securityTokenName="(.+?)".*?securityTokenValue="(.+?)";
A sample test plan (it uses dummy sampler from jmeter plugins, if you don't have them it will faile) is here.
This post here discusses that simply having .*? will match multiple line, but apparently it did not work. This post wast the savior.
Details are from the jmeter documentation are here.
Please note that I have removed the spaces around = to simplify my sample. Please change the regex appropriately.