JMeter XPath results are missing expected items - xpath

Using XPath assertion: //ul/#class after a HTTP request, the assertion returns:
success_message_1=links
success_message_2=accordion vertnav vertnav-top grid-full
success_message_3=grid-full classic
success_message_4=checkout-types
success_message_5=links
success_message_matchNr=5
It is missing exactly one element, which happens to be the success message I need to find. The structure of the success message is:
<ul class="messages"><li class="success-msg"><ul><li>Message</li></ul></li></ul>
Strangely targeting the item with //li[#class="success-msg"] returns nothing. Using jQuery I did a simple jQuery('ul') and it matches all of the <ul> including the missing one.
I've checked the response and the success message does exist in the response, but why can't I select it with XPath?

The correct XPath expression if you need to obtain "Message" "vanilla" XPath selector will look like
//li[#class='success-msg']/ul/li/text()
If your page is not XML/XHTML compliant you may require to enable "Use Tidy" box in your XPath Assertion.
Particularly for your code following XPath Assertion works for me:
//li/text()='Message'
You may wish to use XPath Extractor combiner with Debug Sampler and View Results Tree listener to see what is the output of your XPath queries and once you'll get "true" - the query is OK to be used in the assertion.

Related

difficulty in handling correlation in jmeter

i have identified the dynamic values in my website which i am handling through "regular expression extractor" still when i run the website the login request fails and throw error as token not found. please help,i m struggling...[this image contain the regEx extractor part and the failed login request also][1]
We cannot help you without seeing the response (at least partial) which you're getting for the /-7 request containing this hidden input with the token, you can try locating it using "RegExp Tester" mode of the View Results Tree listener and see whether your regular expression matches something or not
One thing is obvious: using regular expressions for extracting data from HTML is not the best idea, I would recommend considering switching to CSS Selector Extractor instead:

Why is my JMeter XPath assertion failing?

I'm trying to run a simple load test, but some of my XPath assertions are failing and I can't figure out why. Here is a sample of html:
<div class="g1260">
<h1 class="top-head">
<div id="ctl00_mainContent_ctl00">
INVESTMENT CONSULTANTS
</div>
</h1>
</div>
and here is my XPath:
//div[#id="ctl00_mainContent_ctl00" and contains(text(),"INVESTMENT CONSULTANTS")]
The assertion fails, even though, when I look at the response in the results tree, the element is there.
I have also tried the XPaths
//div[#class="g1260"]/h1[#class="top-head"]/div
which fails, and
//div[#class="g1260"]/h1[#class="top-head"]
which passes.
All of the above XPaths work ok in the developer console, but fail in JMeter. What is going on here?
I cannot reproduce your issue, looking into XPath Tester mode of the View Results Tree listener:
Also your expression checks only for node presence, if you need to test whether text equals INVESTMENT CONSULTANTS you will need to amend your XPath expression to look like:
normalize-space(//div[#id="ctl00_mainContent_ctl00"]/text())='INVESTMENT CONSULTANTS'
Depending on the nature of your response you might (or might not) need to tick Use Tidy box, try the both options, if you are using Tidy - check jmeter.log file for any suspicious entries.
If the above steps won't help - share your full response and assertion requirement and we'll try to come up with the most appropriate configuration.
In the meantime check out this XPath Tutorial

Jmeter: String Index Out of Bounds Exceptions on Xpath

Can some one please please help me on this. I am tired of looking into it.
In while loop I am reading data from csv file, navigate to web pages and get Xpath values.
I get String Index out of bounds exceptions on Xpath.
Please see this screenshot of program
Steps to execute were
1.dealers.tt -- HTTP request
2.edit_integrtaion_details.tt --- HTTP request
3.Dealer details -- HTTP Request
then Xpath entities under Dealer details
For some reason some of the records read from file... only 2 steps get executed as below.leaving other steps (3 and Xpath)
dealers.tt
edit_integrtaion_details.tt
then I get an error as
'Dealer details' : java.lang.StringIndexOutOfBoundsException: String index out of range: 8193
I tried selecting redirect automatically and follow redirects in HTTP requests to force step 3 to execute. In both cases get this error.There are no spaces for the name I get from Xpath
Most likely you are sufferin from JTidy issue #205, the options are in:
Uncheck "Use Tidy" box, if your response is valid XML or XHTML it might be the case you don't need it (unlikely though)
Compile latest JTidy from the source code and once done replace jtidy-r938.jar in "lib" folder of your JMeter installation with the brand new JTidy jar.
Switch to CSS/JQuery Extractor
Switch to Regular Expression Extractor
If XPath is totally a must you can also consider JSR223 PostProcessor and Groovy language, it has built-in support of some form of XPath. Check out Groovy Is the New Black article for more details.

Extracting a link with jmeter

So I need to delete an "onclick" dynamic link using jmeter.
Here is the sample of one of the links:
"Delete"
What I need is to extract number and post it in order to do the delete action. Every link is the same except the number.
I have tried to implement some of the solutions I've found on this site but it didn't work.
Thanks in advance
Peace
If you need to do it with XPath you could try going for substring-after function like:
substring-after(//a[text()='Delete']/#href,'param=')
The above expression returns everything which is after param= text in href attribute of a HTML tag having Delete text.
You can test your XPath expressions against actual server response using XPath Tester tab of the View Results Tree listener.
References:
substring-after Function Reference
XPath 1.0 Language Reference
Using the XPath Extractor in JMeter
XPath Tutorial

How can I get the value from a hidden input field using JMeter

I am trying to get the value from a hidden input field. I researched and found many sites ( including instances on this site ) showing great examples. When I try them, I am not able to retrieve the value from this hidden field using the methods I have learned. I have tried both an xpath extractor and a regular expression extractor, but neither one retrieves the value from the hidden field.
Also, I will note that in the tree on the left side in JMeter, I put the extractors as a child to the HTTP Request where the token first appears. Are the extractors supposed to be children or are they supposed to be at the same level as the HTTP Request, but just after it in the flow of the test?
==============================
Here, I will explain my set up. There is an HTTP request from a form. There is a token on the form. I need to get the value for this token. Here is the html for the page where the token appears:
<form action="/folder1/part1/save/12345-1234-1234-1234-123456789012" method="post" name="mgr" id="mgr" >
<input type="hidden" name="token" value="1234-12-12-12-1234" id="token" />
==============================
For the Regular Expression Extractor, I have tried all of these, one at a time for each test run:
//input[#type="hidden" and name="token"]/#value
//input[#type="hidden"][#name="token"]/#value
//input[#type="hidden"]/[#name="token"]/#value
//input[#type="hidden"][#name="token"]/#value/[#id="token"]
//input[#type="hidden"]/[#name="token"]/#value/[#id="token"]
For the XPath Extractor, I have tried all of these, one at a time for each test run:
//[#id="token"]
/html/body/div/div[2]/div/form/input[1]
//html/body/div/div[2]/div/form/input[1]
Try this one: //input[#type="hidden" and #name="token"]/#value
Also, you could test your expressions exactly in JMeter. For example, this xpath extraction you could check in XPath Tester element in View Result Tree Listener. There you could find Regexp Tester too

Resources