Selenium does not find element on page (ruby, watir) - ruby

I can not locate the element on the page in any way, and I would not like to use xpath because the layout of the page can be changed later and complex to maintain.
I tried the following ways:
Page Structure
<select class="form-control errorClass1" id="idPage:idForm10:adhPaymentMethodId" name="adhPaymentMethodId">
<option value="0">Escolha um</option>
<option value="CreditCard">Cartão de Crédito</option>
<option value="Boleto">Boleto</option>
</select>
Attempts
#browser.select_list(:name, "adhPaymentMethodId").click
#browser.option(:text, "Boleto").click
#browser.select_list(:id, "idPage:idForm10:adhPaymentMethodId").click
#browser.option(:text, "Boleto").click
#browser.select_list(:id, "idPage:idForm10:adhPaymentMethodId").option.wait_until_present
sleep 1
#browser.option(:value, "Boleto").click

Try this
#browser.select_list(:name, "adhPaymentMethodId").select("Boleto")
If it's not working, let me know what error it is throwing

Related

How can I use a list of object in the model to automatically populate the options of a select in Thymeleaf view?

I am working on a Spring MVC application that use Thymeleaf for the view.
I am absolutly new in Thymeleaf and I have the following problem.
At this stage of the work into a view I have a select which options values are hard coded into the code, something like this:
<select id="selReg" class="form-control">
<option value="" >--SELEZIONARE UN'AREA--</option>
<option value="areaUmanistica" >Area Umanistica</option>
<option value="areaLinguistica" >Area Linguistica</option>
<option value="areaScientifica" >Area Scientifica</option>
<option value="areaPsicoMotoria" >Area Psico-Motoria</option>
</select>
Now, into my controller, I retrieve a list of Tad1005Tipodisciplina objects using a service and I put this list into the model.
List<Tad1005Tipodisciplina> listaTipoDisciplina = tipoDisiplinaService.getListaTipoDisciplina();
model.addAttribute("listaTipoDisciplina", listaTipoDisciplina);
This Tad1005Tipodisciplina class contain this field:
private String desTipDis;
that I want to use in my view to dinamically show the content of the previous select.
How can I use this list putted into the model to dinamically populate my select options?
You need to iterate through your list using th:each in the select statement. This is where you define a variable that will represent each object in the list, which in turn you can use in each of the option tags like this:
<select id="selReg" class="form-control" th:each="object: ${listaTipoDisciplina}" th:field="*{listaTipoDisciplina}">
<option th:value="${listObject.desTipDis}" th:text="${object.desTipDis}"></option>
</select>
/Edit: A minute too late :)
Solved by myself, in this way:
<select id="selReg" class="form-control">
<option value="" >--SELEZIONARE UN'AREA--</option>
<option th:each="tipoDisciplina: ${listaTipoDisciplina}"
th:value="${tipoDisciplina.codTipDis}"
th:text="${tipoDisciplina.desTipDis}">
</option>
</select>
Posted because maybe it could be util to someone in the future

Find which option is selected

I have this piece of code:
<select id="customizableonly" class=" select" name="product[customizableonly]">
<option value="1">Yes</option>
<option selected="selected" value="0">No</option>
</select>
And I need an xpath string that will find this <select id="customizableonly"...> tag and see which of its 2 options has the attribute selected="selected". Therefore, return the value of the "selected" option (Yes or No). If someone can give a quick solution - I'd appreciate that a lot!
I've got this far //select[#id='customizable'] for acquiring the main tag.
If I get it right, all you have to do is
//select[#id='customizableonly']/option[#selected='selected']/text()

how to make a select box which has a particular value preselected using grails2.0

I have the following line in my gsp
<g:select name="platform" from="['Date','Time','Place','Calendar']"/>
I want the Time option to be automatically selected while loading the page.
<select>
<option value="Date">Date</option>
<option value="Time" selected="selected">Time</option>
<option value="Place">Place</option>
<option value="Calendar">Calendar</option>
</select>
This is what i need when my gsp page got rendered into html.
Please help me
Thanks in advance
You can do it by setting the g:select value
<g:select name="platform" from="['Date','Time','Place','Calendar']" value="'Time'"/>
but it would be better to bind it to an model.

Watir question regarding selecting a hidden dropdown

I have two dropdowns, the second dropdown does not show until a choice is made from the first one. Using watir, i can select the first dropdown, and when i watch it, the second one becomes active, but it cannot select it. i just tried the regular select_list using name and id. Here is the code for the second drop down.
<td>
<input type="hidden" value="1" name="list" id="list">
<script type="text/JavaScript" language="JavaScript"></script>
<select>
<option value="">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
I've also notice the value for the hidden field change as i select different options.
Thanks for any help
The way that I usually access drop down lists is by using this string:
#browser.select_list(:name, "list").set("3")
Does this help?
I usually select hidden dropdowns this way
ie.hidden(:name=>"list").value='2'
Try this:
browserObj = Watir::Browser.new
browserObj.goto('you html in browser')
//browserObj.hidden(:id,"list").value
browserObj.select_list(:name, "list").select_value('2')

dropdown menu question, may be simple may not be

I have a webpage containing input tags like the one below eg.
<input value='Cut' name='container_cut_button' type='submit/>
<input value='Copy' name='container_copy_button' type='submit/>
I want to put these into a dropdown, I was hoping it would be something simple like
<select onchange='submit()'>
<option name='container_cut_button'>Cut</option>
<option name='container_copy_button'>Copy</option>
</select>
but no such luck,
Anyone have any ideas about how this could be done?
Thanks in advance
Use the "value" attribute of the options rather than their name.
<select name="action">
<option value="cut_item">Cut</option>
<option value="save_item">Save</option>
</select>
On the server, you'll check the value of the variable "action." It will be either "cut_item" or "save_item".
I called a javascript function in the select tag ie. onchange="exec(value)", the function gets the select id and inserts the proper name attribute based on it value.
function exec(val){
if(val=='cut'){
document.getElementById("action").setAttribute("name", "cut")
}
}
This worked out ok

Resources