retrieving the max value of all the selects in a page with Xpath - xpath

I want to retrieve max value for each combobox present in a web page, with xpath.
Here is a sample HTML containing several combobox with choices:
<label> <span class="invisible_spoken">Some choice</span>
<select class="select_class">
<option value="0">0</option>
<option value="1" >
1
</option>
<option value="2" >
2
</option>
</select>
</label>
<label> <span class="invisible_spoken">Some choice</span>
<select class="select_class">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</label>
<label> <span class="invisible_spoken">Some choice</span>
<select class="select_class">
<option value="0">0</option>
<option value="1">1</option>
</select>
</label
What I would want to retrieve is the maximum value of each combobox, sample output :
2, 3, 1
I've tried with an expression like :
//table[#id="rooms"]//select[contains(#class, "b_selectbox")]/option[not(//table[#id="rooms"]//select[contains(#class, "b_selectbox")]/option/#value > #value)]/#value
But it is returning just combobox max values of the maximum combo value, in the sample case just 3 that is the highest, in the case there will be two combobox with maximum values equals to 3, then it will return those 2 ...

Xpath Selector for Options with highest value.
//label/select[#class="select_class123"]/option[not(../option/#value > #value)]
o/p: Option elements with highest values.
(//label/select[#class="select_class"]/option[not(../option/#value > #value)])/#value
o/p: 2, 3, 1
Test XML XPath online:
<select class="select_class">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<select class="select_class">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select class="select_class">
<option value="0">0</option>
<option value="1">1</option>
</select>

Related

USA States Picklist on Visualforce Page

I have a Visualforce page form to create Leads in Salesforce
In the form I want to add the State Picklist.
On the Lead object Address is a composite field. As per documentation, the State field is as seen here -
Field Name
Field Label
Type
Length
State
State/Province
String
80
I want the State on the visualforce page to look like this. i.e when I click on Select a State , I should see the list of State that i can choose from.
This is the CSS code I tried
<label for="state">State</label>
<select name="state" id="state">
<option value="" selected="selected">Select a State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select> <br>
Can someone please guide, how I could translate this to VFP to use the following tag
<apex:selectOptions value="{!State}" /
No no, the value user selected ({!Lead.State}) should be bound to parent tag, not to <apex:selectOptions>. SelectOptions is just list of choices. And then you render them as a picklist (normal or multiselect), list of checkboxes, list of radio buttons... How you use them is separate from how they're defined, which values (if any are disabled...)
If you want to keep it in pure Visualforce - look into <apex:selectOption>, you could run some search-replace on your code and you're almost there. If you want to generate the list in Apex (if you need it for something else, maybe validations? Maybe you'd want to store it in config object or custom metadata and then admin can tweak the lists without code changes?) - <apex:selectOptions> and you pass to it a List<SelectOption>.
If your implementation is only US-specific then maybe you should look into config solution rather than code. https://help.salesforce.com/articleView?id=sf.admin_state_country_picklists_configure.htm&type=5

How to use nested loop in Vue JS?

Here I Want to use foreach loop inside foreach loop in select option...
<select class="form-control" style="width: 100%;" v-model="category_id" >
<option value="0">Select Main Category</option>
<optgroup v-for='section in categories' v-bind:label="section.name">
<option v-for='category in section.categories' :value="category.id"> - {{category.category_name}}
</option>
<option v-if="" v-for="subCategory in category.sub_categories"> -- {{subCategory.category_name }}</option>
</optgroup>
But its not working ....
<option v-if="" v-for="subCategory in category.sub_categories">
category is not defined at this point, it is defined in v-for in the option above this, which is closed before you get to this. so that you will get sub_categories of undefined
change like below will work
<select class="form-control" style="width: 100%;" v-model="category_id" >
<option value="0">Select Main Category</option>
<optgroup v-for='section in categories' v-bind:label="section.name">
<optgroup v-for='category in section.categories' :value="category.id"> - {{category.category_name}}
<option v-if="" v-for="subCategory in category.sub_categories"> -- {{subCategory.category_name }}</option>
</optgroup>
</optgroup>

drop down list default value

I'm trying to use a drop down list with a default value equals nothing
but nothing means zero and every time i try, it says that i cant divide by zero
how can i make the default value equal null not zero ?
<form method="post" action="try.php"name="test">
<select name="xx">
<option selected=""></option>
<option value="1">1</option>
<option value="3">3</option>
<option value="5">5</option>
<option value="7">7</option>
<option value="9">9</option>
</select>
<br /><input type="submit" name="submit" value="PROSES" />
</form>
<?php
if(isset($_POST['submit'])){
$x=$_POST['xx'];
$z=1/$x;
}
?>

continued example - cannot find watir element

In Cannot click html element with watir, i was trying to click an element which gives me the row below:
I am not able to find the three dropdown lists which you see in the image above.
How do I do it ? Each time, the id of the dropdown elements changes.
For example, the middle one html code is:
<td>
<select id="filtersJob6_intrinsic_enumOperator" name="filtersJob6_intrinsic_enumOperator" onchange="if(top.document.getElementById('filtersJob6_intrinsic_enumOperator').value=='isNull'||top.document.getElementById('filtersJob6_intrinsic_enumOperator').value=='isNotNull'){top.document.getElementById('filtersJob6_intrinsic_operand1Container').style.display='none';}else{top.document.getElementById('filtersJob6_intrinsic_operand1Container').style.display='inline';}">
<option value="equals" selected="selected">equals</option>
<option value="notEqual">not equals</option>
<option value="isNull">is not set</option>
<option value="isNotNull">is set</option>
</select>
</td>
The id id="filtersJob6_intrinsic_enumOperator" can have any number 4,7,6,5 etc.
How do I make the watir find this element ?
EDIT -
Here is the code for the first dropdown:
<select id="filtersJob3_intrinsic_name" name="filtersJob3_intrinsic_name" onchange="var shown=0;top.document.getElementById('filtersJob3_intrinsic_operator').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand2').style.display='none';top.document.getElementById('filtersJob3_intrinsic_dateOperator').style.display='none';top.document.getElementById('filtersJob3_intrinsic_enumOperator').style.display='none';top.document.getElementById('filtersJob3_intrinsic_listOperator').style.display='none';top.document.getElementById('filtersJob3_intrinsic_uuidOperator').style.display='none';top.document.getElementById('filtersJob3_intrinsic_datehelp1').style.display='none';top.document.getElementById('filtersJob3_intrinsic_datehelp2').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand1abortStatus').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand1outcome').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand1priority').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand1status').style.display='none';top.document.getElementById('filtersJob3_intrinsic_operand1errorCode').style.display='none';if(top.document.getElementById('filtersJob3_intrinsic_name').value=='abortStatus'){shown=1;top.document.getElementById('filtersJob3_intrinsic_enumOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1abortStatus').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2Container').style.display='none';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='outcome'){shown=1;top.document.getElementById('filtersJob3_intrinsic_enumOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1outcome').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2Container').style.display='none';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='priority'){shown=1;top.document.getElementById('filtersJob3_intrinsic_enumOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1priority').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2Container').style.display='none';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='status'){shown=1;top.document.getElementById('filtersJob3_intrinsic_enumOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1status').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2Container').style.display='none';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='errorCode'){shown=1;top.document.getElementById('filtersJob3_intrinsic_enumOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1errorCode').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2Container').style.display='none';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='jobId'){shown=1;top.document.getElementById('filtersJob3_intrinsic_uuidOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2Container').style.display='none';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='createTime'){shown=1;top.document.getElementById('filtersJob3_intrinsic_dateOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp2').style.display='inline';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='finish'){shown=1;top.document.getElementById('filtersJob3_intrinsic_dateOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp2').style.display='inline';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='modifyTime'){shown=1;top.document.getElementById('filtersJob3_intrinsic_dateOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp2').style.display='inline';}if(top.document.getElementById('filtersJob3_intrinsic_name').value=='start'){shown=1;top.document.getElementById('filtersJob3_intrinsic_dateOperator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_datehelp2').style.display='inline';}if(!shown){top.document.getElementById('filtersJob3_intrinsic_operator').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operator').onchange();top.document.getElementById('filtersJob3_intrinsic_operand1').style.display='inline';top.document.getElementById('filtersJob3_intrinsic_operand2').style.display='inline';}">
<option value="abortStatus" selected="selected">Abort Status</option>
<option value="abortedBy">Aborted By</option>
<option value="createTime">Create Time</option>
<option value="directoryName">Directory Name</option>
<option value="elapsedTime">Elapsed Time</option>
<option value="errorCode">Error Code</option>
<option value="errorMessage">Error Message</option>
<option value="finish">Finish Date & Time</option>
<option value="credentialName">Impersonation Credential</option>
<option value="jobId">Job ID</option>
<option value="jobName">Job Name</option>
<option value="lastModifiedBy">Last Modified By</option>
<option value="launchedByUser">Launched By User</option>
<option value="licenseWaitTime">License Wait Time</option>
<option value="liveProcedure">Live Procedure</option>
<option value="liveSchedule">Live Schedule</option>
<option value="modifyTime">Modify Time</option>
<option value="outcome">Outcome</option>
<option value="owner">Owner</option>
<option value="priority">Priority</option>
<option value="procedureName">Procedure Name</option>
<option value="projectName">Project Name</option>
<option value="resourceWaitTime">Resource Wait Time</option>
<option value="runAsUser">Run As User</option>
<option value="scheduleName">Schedule Name</option>
<option value="start">Start Date & Time</option>
<option value="stateName">State Name</option>
<option value="status">Status</option>
<option value="totalWaitTime">Total Wait Time</option>
<option value="workspaceWaitTime">Workspace Wait Time</option>
</select>
You can use a regular expression in your locator:
browser.select_list(:id => /filtersJob\d+_intrinsic_enumOperator/).select value_to_select
In this example, the regular expression is denoted by opening and closing forward slashes, and the digit within the original string is replaced with \d+, which means "one or more digits".
EDIT:
Given this minimal HTML snippet:
<select id="filtersJob6_intrinsic_enumOperator">
<option value="isNull">is not set</option>
<option value="isNotNull">is set</option>
</select>
Use select to choose on option based on text:
b.select_list(:id => /filtersJob\d+_intrinsic_enumOperator/).select 'is set'
Use select_value to choose an option based on the value attribute:
b.select_list(:id => /filtersJob\d+_intrinsic_enumOperator/).select_value 'isNotNull'

th:selected a number in a select/option with Thymeleaf doesn't work

I have this code
<div th:class="form-group">
<td><label class="control-label leftMargin10 rightMargin10" scope="col" th:text="#{insertHours.hhFrom}">Attivita'</label></td>
<td><select class="form-control" th:field="*{hhFrom}">
<option th:each="i : ${#numbers.sequence(0, 23)}" th:value="${i}" th:text="${i}" th:selected="${ i==9 } ">Options</option>
</select>
</td>
</div>
When I try to add a condition in th:selected it doesn't work.
I have also replaced with this code:
th:attr="${i==9}? selected=selected: '' "
but the result is the same.
The HTML
<select class="form-control" id="hhFrom" name="hhFrom">
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
</select>
Thanks in advance to answers
You cannot use th:field along with th:selected.
If you replace th:field with name=someMeaningfullName the code will work just fine.
Check out this thread on the Thymeleaf forum for more information
Another hack that, is pretty simple and works, is to close the select tag: <select ... />
Please note /> at the end of first line:
<select th:field="*{percentage}" />
<option th:each="i : ${#numbers.sequence(0, 100)}" th:value="${i}" th:text="${i}" th:selected="${i==75}"></option>
</select>
Renders as:
<select id="percentage" name="percentage" />
<option value="0">0</option>
<option value="1">1</option>
...
<option value="74">74</option>
<option value="75" selected="selected">75</option>
<option value="76">76</option>
...
<option value="100">100</option>
</select>
Both web browser and Thymeleaf will handle this fine.
I used Thymeleaf v.3.0.9.RELEASE
Also I found out that if you put <div> tag around option fields, selected="selected" will also work. e.g
<select th:field="*{name}">
<div>
<option disabled="true" selected="selected" value="">Select</option>
<option value="1">first</option>
<option value="2">second</option>
</div>
</select>

Resources