regex using dynamic input in Jmeter(regex extractor) - jmeter

I have a query regarding Jmeter regex extractor. I am trying to implement 1 scenario however not able to do same. Below are the details:
Requirement :
In Jmeter I have defined user defined variable : String VAR = KZ
now I am trying to use Regex extractor so that from the HTML response, regex will match VAR value in HTML(defined below) and will fetch span class name, as I need to set checkbox ON for KZ.
Requirement is to handle checkbox ON functionality through user defined variable, that means I don't want to hardcode class name instead based on user defined variable(which will be td value i.e. in this example KZ) I have to fetch class name using Regex Extractor. Could someone please help how to proceed?
Below is HTML Code:
<tr class="trClass">
<td style="width: 13.5%;">
<span class="checkbox"><input id="ctl00ctl94" type="checkbox" name="$ctl95$"
onclick="return validatecheck();" /></span>
</td>
<td style="width: 41.2%;"> KZ </td>
<td style="width: 0%; display: none;"> 5581357 </td>
<td style="width: 32%;"> 06/03/2018 2:22:38 PM </td>
</tr>
<tr class="trClass">
<td style="width: 13.5%;">
<span class="checkbox"><input id="ctl00ctl95" type="checkbox" name="$ctl95$"
onclick="return validatecheck();" /></span>
</td>
<td style="width: 41.2%;"> TM </td>
<td style="width: 0%; display: none;"> 5581358 </td>
<td style="width: 32%;"> 06/03/2018 2:22:38 PM </td>
</tr>
<tr class="trClass">
<td style="width: 13.5%;">
<span class="checkbox"><input id="ctl00ctl96" type="checkbox" name="$ctl96$"
onclick="return validatecheck();" /></span> </td>
<td style="width: 41.2%;">TR </td>
<td style="width: 0%; display: none;"> 5581359 </td>
<td style="width: 32%;"> 06/03/2018 2:22:38 PM </td>
</tr>

Using regular expressions for parsing HTML is not the best idea as:
they are hard to develop and/or maintain
they are very sensitive to markup change hence fragile, i.e. if order of attributes changes or something will go to a new line - it will simply ruin your regex
So I would recommend going for another post-processor which can work with DOM directly, for instance XPath Extractor
The relevant XPath query which will fetch the classname of span which is above the KZ text would be something like:
//td[contains(text(),'KZ')]/preceding::*/span/#class
Of course you can substitute KZ with the JMeter Variable reference, i.e.
//td[contains(text(),'${VAR}')]/preceding::*/span/#class
However you will not be able to test your queries using XPath Tester mode of the View Results Tree listener, you will have to go for Debug Sampler instead to visualize the resulting variable.
Check out XPath Tutorial and Using the XPath Extractor in JMeter guide to get familiarized with XPath language.
Also be aware that according to JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages.
So I don't believe fetching the span classname will solve your problem, most probably you will need to send underlying input name as a parameter so you should be looking for
//td[contains(text(),'KZ')]/preceding::*/span/input/#name

Related

How do I bind a value to a TCustomAttribute in Aurelia?

I'm trying to achieve the following result: I have a set of values that are coming from an array which I iterate over in order to populate an HTML table. As well I have an icon that user can hoover-over and can see data in there coming from the array and a translation key coming from translation files.
I want to bind a second argument to the TCustomAttribute in order to display to the user another data that was edited by them.
How do I achieve this in Aurelia?
<template>
<table>
<thead>
<th><span>Id</span></th>
<th><span>Name</span></th>
<th><span>Description</span></th>
<th><span>Date</span></th>
</thead>
<tbody>
<tr repeat.for="item of data">
<td><span>${item.Id}</span></td>
<td><span>${item.Name}
<a data-toggle="popover" t="[data-content]pending_name ${data.Name}" data-trigger="hover">
<i class="fa fa-info-circle"></i>
</a>
</span></td>
<td><span>${item.Description}</span></td>
<td><span>${item.Date}</span></td>
</tr>
</tbody>
</table>
</template>
Take a look at the t-params attribute which allows you to pass in additional parameters. More about that in the official guide http://aurelia.io/docs/plugins/i18n#using-the-plugin

how to find the root node on the basis of text of two attributes

I have a dynamic web table and I want to select the node on the basis of text value of two different text attributes.
//tr[.//td[contains(text(),'SATWIK GHANSIYAL')] and .//td[contains(text(),'07/07/2002')]]
HTML:
<html><head></head><body><table>
<tbody><tr style="background-color:White;height:24px;">
<td class="gridtext" align="center">
<span class="checkboxclass"><input id="ctl00_ContentPlaceHolder1_grdUsers_ctl02_chkSelect" type="checkbox" name="ctl00$ContentPlaceHolder1$grdUsers$ctl02$chkSelect" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$grdUsers$ctl02$chkSelect\',\'\')',
0)"></span>
</td><td class="gridtext" align="left" style="background-color:#FDE9D9;">SATWIK GHANSIYAL</td>
<td class="gridtext" align="left" style="background-color:#FDE9D9;" xpath="1">RAJESH GHANSIYAL</td>
<td class="gridtext" align="left" style="background-color:#FDE9D9;">SHELLY</td>
<td class="gridtext" align="left" style="background-color:#FDE9D9;">07/07/2002</td>
</tr>
</tbody></table>
</body></html>
I am getting the massage no element found
use this.
//tr[.//td[contains(.,'SATWIK GHANSIYAL')] and .//td[contains(.,'07/07/2002')]]
trying to evaluate this expression based on the given xml
//tr[.//td[contains(text(),'SATWIK GHANSIYAL')] and .//td[contains(text(),'07/07/2002')]]
text() is returning multiple sequence, thus giving me this error message.
Unable to perform XPath operation. A sequence of more than one item is not allowed as the first argument of contains() ("", "")

How to XPATH for Table element which have dynamic Ids

I have to get the XPATH for dynamic Ids . The code look like this
<table width="100%" role="presentation">
<tbody>
<tr>
<tr>
<td id="DWT10" role="presentation">
<div id="zl__TV-main__rows" class="DwtListView-Rows" style="height: 130px; width: 377px;">
<div id="zli__TV-main__654" class="RowDouble RowEven " role="treeitem" tabindex="0" aria-label="Unread, hello everyone, Wilkerson, 12:26 AM" aria-posinset="1" aria-level="1">
My XPATH goes like this :
//div[starts-with(#id='zl__CLV-main') and ./div [contains(#aria-posinset,'1')]]
I am getting:
Could not evaluate XPATH error.
XPAth only works if you have a valid XML source file. In your example there are no closing tags.
Your XPATH is invalid. the start-with function must be changed to
//div[starts-with(#id,'zl__CLV-main')
comma instead of =

selenium webdriver xpath generation

I want to create an xpath for clicking on "run " (4th column) based on the first column value (xyz). the below xpath doesnt work. Can you suggest a better way of writing the xpath.
//table/tbody/tr/td[text()='xyz fix']/parent::tr/td[4]
<div id="main">
<table class="FixedLayout" width="1000px">
<tbody>
<tr></tr>
<tr>
<td class="RowHeight">
xyz
</td>
<td>xyz fix</td>
<td>1125</td>
<td>
Run
</td>
</tr>
<tr>
<td class="RowHeight">
abc
</td>
<td>abc fix</td>
<td>1125</td>
<td>
Run
</td>
</tr>
</tbody>
</table>
</div>
I don't see why your one didn't work. Please clarify what it means "doesn't work". NoSuchElementException? ElementNotVisibleException? Wrong XPath? Not clicking the link or what?
Meanwhile, try the following XPaths (but the issue could be your Selenium code instead of XPath):
Here I assume you want to the <a> link instead of <td>, because you mentioned you want to click it.
Use XPath predicate:
//*[#id='main']//table/tobdy/tr[td[text()='xyz']]/td[4]/a
Use XPath predicate with attribute selector to avoid using index.
//*[#id='main']//table/tobdy/tr[td[text()='xyz']]//a[contains(#href, 'Instance/Create')]
Use .. to get the parent
//*[#id='main']//table/tobdy/tr/td[text()='xyz']/../td[4]/a

Selenium IDE: How to detect the xpath's if div id's , class are randomly generated every time?

I am trying to detect the xpath or css but everytime I run the script, the div id's and class names change which there by fails the script.
<div class="yui-dt-bd" style="height: 300px; width: 100%;">
<table id="yuievtautoid-0" summary="" style="margin-top: 0px;">
<tr id="yui-rec28" class="yui-dt-rec yui-dt-first yui-dt-even yui-dt-selected" style="">
<td id="yui-gen52" class="yui-dt23-col-professorId yui-dt-col-professorId yui-dt- sortable yui-dt-first" headers="yui-dt23-th-professorId ">
<div id="yui-gen51" class="yui-dt-liner">1</div>
</td>
<td id="yui-gen44" class="yui-dt23-col-professorName yui-dt-col-professorName yui-dt-sortable yui-dt-last" headers="yui-dt23-th-professorName ">
<div id="yui-gen43" class="yui-dt-liner">John Power</div>
</td>
</tr>
</table>
</div>
I had written xpath=//*[#id="yui-gen46"], but id's keep changing. Tried writing table id too. But it does not work.
xpath=id('yuievtautoid-1').
Appreciate some input .
You can specify a part of class or id that is not changed. For example:
//*[contains(#class, 'col-professorName')]
or
//*[contains(#id, 'yuievtautoid')]
or CSS versions:
css=*[class*="col-professorName"]
css=*[id^="yuievtautoid"]

Resources