I have a webpage where this code is:
<select tabindex="8" id="custom_field_4" name="custom_field_4[]" size="4" multiple="multiple" xpath="1">
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="green" selected="selected"> green</option>
<option value="flashing" selected="selected"> flashing</option>
</select>
I need to get all the option values.
I tried
Get List Items //select[#name="custom_field_4[]"] but I get the error: List with locator \'//select[#name="custom_field_4[]/option"]\' not found.'
If you check the source code (line 333) of the Selenium library, you can see that the Get List Items keyword use list as tag name whereas in your DOM it is select. It won't match.
def _get_select_list(self, locator):
el = self.find_element(locator, tag='list')
return Select(el)
You can get all list elements using the Get WebElements keyword instead like:
${list elements}= Get WebElements //select[#id='custom_field_4']/option
You can access the value attribute of each element in the returned list.
Related
I'm using a list to display all of the names of the application stored in the database. The problem is that I want the first element of the dropdown list to be empty.
<div class="col-lg-10">
<select>
#foreach (var item in Model.Application)
{
<option value="#item.Application_Name">
#item.Application_Name
</option>
}
</select>
</div>
At the moment the dropdown is working I just want the first element to be empty.
I want the dropdown in the view to be get filled with value set from the controller. In my controller using model attribute I have added the list limits
#RequestMapping(value = "/works", method = RequestMethod.GET)
public String searchWorks(Model model){
Map< Integer, String > limits = new HashMap<Integer, String>();
limits.put(20, "20件");
limits.put(25, "25件");
limits.put(30, "30件");
limits.put(35, "35件");
limits.put(40, "40件");
limits.put(45, "45件");
limits.put(50, "50件");
model.addAttribute("limits",limits);
model.addAttribute("limit",limit);
return "workSituation";
}
In view Page in order to populate the dropdown with the value set using model attribute I have used this code
<div class="col-sm-3">
<select class="form-control" name = "limit" id="limit" onchange="getList(this.value)">
<option selected>-- select number of items--</option>
<option data-th-each="limit : ${limits}"
data-th-value="${limt.getKey()}"
data-th-text="${limt.getValue()}" >
</select>
</div>
I am getting the error
caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "limt.getKey()"
caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "limt.getValue()"
What will be the cause for this. Actually dropdown is iterating 7 times(the number of records in the limits list) but the key and value is not able to fetch with code.What is the correct way to get the dropdown filled with
<option value="20">20件</option>
<option value="25">25件</option>
<option value="30">30件</option>
<option value="35">35件</option>
<option value="40">40件</option>
<option value="45">45件</option>
<option value="50">50件</option>
For thymeleaf try the following
<option th:each="limit : ${limits.entrySet()}" th:value="${limit.key}" th:text="${limit.value}"></option>
I am using Ractive and have two select lists. The first select list lets the user select their country. If they select "US", Ractive will check for it and display a list of states for the user to select their state. For example:
<select value="{{country}}">
<option value="CA">Canada</option>
<option value="US">USA</option>
</select>
{{#if country == 'US'}}
<select value="{{chosen_state}}">
{{#states}}
<option value="{{this.state_name}}">{{this.state_name}}</option>
{{/}}
</select>
{{/if}}
When this form first loads "Canada" is selected by default. Once the user selects "US", the states list shows up just fine. However, if I try to check the value of "chosen_state", it is set to empty rather than the first state in the states list. After I manually change the state, then and only then does the "chosen_state" value show as a state value.
Do I have to wait for the change event to be triggered by a manual event, or is there some way to make it so that as soon as the states list is rendered, it will update it's value automatically based on the first state displayed? It would be nice to not have to trigger a change event for every select list when it's rendered.
It turns out that this requires a dirty check using updateModel. I made it so if the select field is changed, it triggers an event that calls updateModel on the instance to dirty check the chosen_state field.
Updated selected code:
<select value="{{country}}" on-change="countrychange">
<option value="CA">Canada</option>
<option value="US">USA</option>
</select>
{{#if country == 'US'}}
<select value="{{chosen_state}}">
{{#states}}
<option value="{{this.state_name}}">{{this.state_name}}</option>
{{/}}
</select>
{{/if}}
And in ractive:
ractive.on('countrychange', function(event) {
this.updateModel();
});
Alternate solutions might include observing the model for updates to the country then running this.updateModel() as well as just running updateModel on the required keypath which is more efficient.
Further documentation on this can be found at:
http://docs.ractivejs.org/latest/ractive-updatemodel
I have a dropdown that gets its items from database. The default value to be selected in this dropdown is retrieved from a cookie.
The problem is,
1. there is an empty option tag as the first option and also,
2. the default value is not selected.
There is no issue at all when I use v1.3.16. This happens when using v1.2.0. (I have to use only v1.2.0)
How to fix this.
ASPX:
<select id="ddlItems" data-ng-model="ItemId">
<option value="-1">-- All Circles --</option>
<option data-ng-repeat="item in Items" value="{{item.AreaCode}}"
data-ng-selected="item.AreaCode==ItemId">{{item.AreaName}}</option>
</select>
Ctrl.js:
var promise = MyFactory.GetItems();
promise.then(function (success) {
if (success.data != null && success.data != '') {
var data = success.data;
$scope.Items = data.lstItems; //bind items to dropdown
$scope.ItemId = itemIdFromCookie; //select default value
alert(itemIdFromCookie); //it pops -1
}
else {
console.log(success.data);
}
}
Rendered HTML:
<select id="ddlItems" data-ng-model="ItemId">
<option value="? string:"-1" ?"></option>
<option value="-1">-- All Circles --</option>
//...other options
</select>
Try to use ngOptions instead
Like this
<select id="ddlItems"
data-ng-model="ItemId"
ng-options="item.AreaCode as item.AreaName for item in Items">
<option value="-1">-- All Circles --</option>
</select>
This happens becausedata-ng-model="ItemId" is empty when your model is App is Loaded.
To Have some initial value. you can put default value in ng-init
For Ex : data-ng-init='data-ng-model="--SELECT--";'
Or per your Array list Item which you are getting from database set one of the values.
Remember init will get triggered b/f you complete the Ajax Call.
I'm trying to using thymeleaf as the view template and i come across one problem. the code I have now is as below.
<select>
<option th:each="res: ${result1}"
th:value="${result1.NAME}"
th:text="${result1.NAME}"></option>
</select>
What I need is like this, where I dont know how to add another attribute for result2, both result1 and result2 are the list object in the controller
<select>
<option th:each="res: ${result1}"
th:value="${res.NAME}"
th:text="${res.NAME+result2.SCHOOL}"></option>
</select>
You can create a simple object with two fields for result1 and result2, if you know their relationship in the controller. Then you can use a list of that objects to iterate in html page.
<select>
<option th:each="item: ${itemList}"
th:value="${item.result1.NAME}"
th:text="${item.result1.NAME + item.result2.SCHOOL}"></option>
</select>