Regular Expression for Extracting values from dropdown in Jmeter - jmeter

To start with - I am new to writing regular expressions.
I have two dropdowns as FromCity and ToCity which ate HTML options (as dropdowns). However both are having same left right boundary due to which not able to extract the specific values of a drop down at runtime.
e.g.
FROM CITY DROPDOWN
<select name="fromPort" class="form-inline">
<option value="Paris">Paris</option>
<option value="Philadelphia">Philadelphia</option>
<option value="Boston">Boston</option>
<option value="Portland">Portland</option>
<option value="San Diego">San Diego</option>
<option value="Mexico City">Mexico City</option>
<option value="São Paolo">São Paolo</option>
</select>
TO CITY DROPDOWN
<select name="toPort" class="form-inline">
<option value="Buenos Aires">Buenos Aires</option>
<option value="Rome">Rome</option>
<option value="London">London</option>
<option value="Berlin">Berlin</option>
<option value="New York">New York</option>
<option value="Dublin">Dublin</option>
<option value="Cairo">Cairo</option>
</select>
I can fetch the city names with - <option value="(.*?)"> but not able to distinguish which value is for which dropdown.
Is there a better way to handle this using regular expression ?

Using regular expressions for parsing HTML is not the best option, I would rather suggest using CSS Selector Extractor instead
This way you will be able to get "from" city names as select[name=fromPort] option and "to" city names as select[name=toPort] option
Demo:
More information:
CSS Selectors Reference
How to Use the CSS/JQuery Extractor in JMeter

Related

october cms ajax and options values

Is it possible to send value from options on example like this where x need to be value from option. This select im using on partial and ajax works with manualy added value as x. THX!
<select data-request-data = "id: x " class="form-control custom-select" data-request="onChangeValue">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
Just give your select a name, an unique name.
name="some_unique_name"
<select name="my_super_special_name_for_select" class="form-control custom-select" data-request="onChangeValue">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
</select>
Then when you change the value the value of the field is sent along in post
The result of:
public function onChangeValue()
{
traceLog(post());
}
In the log you will see then a result corresponding to
["my_super_special_name_for_select" => 5 ]
So you can fetch it with post('my_super_special_name_for_select') or whatever name you have given the select element to get the value.
public function onChangeValue()
{
$id = post('my_super_special_name_for_select');
}
Yes you can send value from select. But for this you will need to put it inside a form and then call data request on it. Value will be sent as part of post(). It can't be sent dynamically like the way you are using. if you can elaborate your external conditions more I can suggest other solutions too.

How to do Correlation for below scenario

I need the value beside "selected" in below for correlation
Code:
id="ctl00_ContentPlaceHolder1_GVMembers_ctl04_ddlRelation" class="ddl" style="width:100px;">
<option selected="selected" value="6">Husband</option>
<option value="1">Wife</option>
<option value="2">Father</option>
<option value="3">Brother</option>
<option value="4">Sister</option>
<option value="5">Daughter</option>
<option value="7">Spouse</option>
<option value="8">Son</option>
<option value="9">Mother</option>
<option value="10">Mother In Law</option>
<option value="11">Brother In Law</option>
<option value="12">Father In Law</option>
<option value="13">Others</option>
but cannot use regex because client is using LR9.1
also when save param is to capture ""
the ord is changing for every vuser.
Please help me with this.
And also the Selected values will also me changing from 1 to 13.
Thank You
You can use <option selected="selected" as LeftBounddary and </option> as Right Boundary,which will fetch value="6">Husband
And to get the value(i.e Husband) you have to do some string manipulation
Eg:- strtok function using > as delimiter
You can use a regular expression:
web_reg_save_param_regexp(
"ParamName=SelectedOption",
"RegExp=selected\" value=\"\\d+\">(.*?)<\/option>",
LAST);
That will only grab the 'husband' part, if you want the option number you can use:
web_reg_save_param_regexp(
"ParamName=SelectedOption",
"RegExp=selected\" value=\"(\\d+)\">.*?<\/option>",
LAST);

Change dropdowns with same .class name

I have three dropdowns with same class name:
<select class="MyClass">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="MyClass">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="MyClass">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
I want to change any of these dropdown values based on any other dropdrop selected. If I select option two from second dropdown - I want 1st and 3rd dropdown values to be two. All these dropdown should change values no matter which one I select.
Thanks.
You will need JavaScript to do this. Here is an code example using jQuery:
$('.MyClass').on('change',function(){
$('.MyClass').val( $(this).val() );
});
This will add an EventListeneer for the change Element and update all DropDowns to the value of the changed one.
http://jsfiddle.net/CWP7Q/
you can use jQuery or normal JS, but my example contains Jquery, which will give you an idea. Please check the example in Jsfiddle.
The example binds a change event to the class name of the three selectors:
$(".MyClass").change(function(){
$(".MyClass").val($(this).val());
});
and Voila, every selector gets changed.
Somehting like (with jQuery)
$('.MyClass').change(function() {
$('.MyClass').val($(this).val());
});

jquery picklist where select option values are not numeric

The jquery picklist plugin only seems to work if the value of the options in the select are numeric e.g.
<select>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
</select>
as opposed to:
<select>
<option value="one">Value 1</option>
<option value="two">Value 2</option>
</select>
Is there an alternative or workaround to this that doesn't involve changing the objects populated in the list to have a numeric property?
This was a known bug that has been fixed. As of version 0.9.0, the jquery-picklist widget supports non-numeric option values. Update to the latest version for the fix.
See the Non-Numeric Values Test for a demonstration of non-numeric values.

Html select dropdown list - how to choose the selected value from server code

I have a select list say of states in the country, which i have in a helper to include easily in any form. (removing most options to make it brief).
I have the value of the current selection stored in the database say "CA". How would i set selected="true" to option CA before rendering the list to the user?
#helper StateSelect(string name = "State")
{
<select name="#name" id="#name" class="required">
<option value="">-- Select -- </option>
<option value="AK">Alaska</option>
<option value="AL">Alabama</option>
<option value="AR">Arkansas</option>
<option value="AZ">Arizona</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="VA">Virginia</option>
<option value="VT">Vermont</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
}
As Darin Dimitrov says, the built-in stuff would be better. However, if you do need to, I think you have a few options:
Add code like this to every line:
<option value="CA" #(name == "CT" ? "selected=selected" : "")> Connecticut</option>
Just re-add the selected item to the top of the list
This keeps the code cleaner, the selected option is just repeated at the top (and selected there), before the entire list

Resources