Watir question regarding selecting a hidden dropdown - ruby

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')

Related

Thymeaf Calculated URL Value

I need to get a value from the select component of my page and set its value as a parameter in the href.
<td class="body-item mbr-fonts-style display-7"><a th:href="#{/export(exportEntity='Person',semester='javascript:document.getElementById(\'semester\').value')}">Download</a></td>
Semeter variable has the value at my server side:
semester = javascript:document.getElementById('semester').value
and not the dropdown value.
Unfortunately, this code is not picking the value from the select component. Any guess what I have done wrong here.
Thymeleaf runs on the server, while JavaScript runs on the browser. You can't mix it like that.
It's difficult to say what to do, because your question is lacking context, specifically: What is the element with the id semester?
If it's a select element (or another form element), then it would be possible to use neither Thymeleaf nor JavaScript, but a simple form:
<form method="get" action="/export">
<input type="hidden" name="exportEntity" value="Person">
<select name="semester">
<option value="A">Semester A</option>
<option value="B">Semester B</option>
</select>
<input type="submit" value="Download">
</form>
Clicking on the button will have the browser generate an URL such as /export?exportEntity=Person&semester=A and go to it.

Capybara Datalist Select not visible

I have the following HTML snippet:
<input type="text" id="manufacturer" list="manufacturers" placeholder="Search by manufacturer name or supplier code" class="form-control form-control-2-3" value="" name="manufacturer">
<datalist id="manufacturers">
<select>
<div>
<option value="Jaguar">AA</option>
<div></div>
</div>
<div>
<option value="Audi">AB</option>
<div></div>
</div>
<div>
<option value="Mercedes">AC</option>
<div></div>
</div>
</select>
</datalist>
It's a dropdown menu and I want to select one of the options. No matter what I try with any find command or select function. I always get the same error:
Selenium::WebDriver::Error::ElementNotVisibleError: element not visible: Element is not currently visible and may not be manipulated
Does anyone have any suggestions on how to scope to those options and select one?
Thanks.
What you're trying to do isn't currently possible because it's not actually a dropdown select element. The <datalist> option elements are never actually visible on the page because the standard states "In the rendering, the datalist element represents nothing and it, along with its children, should be hidden." - https://html.spec.whatwg.org/dev/form-elements.html#the-datalist-element . Instead any <option> elements in the datalist are just used as autofill suggestions for the input element (but don't actually restrict the value a user can input in any way). Because of this and since the datalist user can just type anything they want into the input element you can set the input value like any other text input.
fill_in("manufacturer", with: 'Jaguar')

ElementNotVisibleError - A Specific Watir-Webdriver Issue

Trying to do
b.select_list(:name => "bedroomsMin").select '3+ Beds'
on
<div class="beds col-sm-2 hidden-xs">
<div class="form-group">
<select class="form-control wide" name="bedroomsMin">
<option value="null">All Beds</option>
<option value="0">0+ Beds</option>
<option value="1">1+ Beds</option>
<option value="2">2+ Beds</option>
<option value="3">3+ Beds</option>
<option value="4">4+ Beds</option>
<option value="5">5+ Beds</option>
</select>
</div>
</div>
but get the following error:
element not visible: Element is not currently visible and may not be manipulated (Selenium::WebDriver::Error::ElementNotVisibleError).
This list selector is contained in a dropdown element that is clicked like this:
b.link(:class => 'btn-open-filers').when_present.click
How can I select if it's not visible? Is there a way to force visibility?
Sounds like a timing issue. When the link is clicked, the dialog containing the select list may not appear before Watir tries to interact with it.
Try waiting for the select list:
b.select_list(:name => "bedroomsMin").when_present.select '3+ Beds'
Looks like the <div class="beds col-sm-2 hidden-xs"> having hidden may have something to do with it.
Also it appears you're are only checking for when the element is present, which is to say if it loads in the html but is not visible it'll still return true.
Here's a quick read on that:
What's the difference between `visible?` and `present?`?
Since you have it clicking the dropdown after it checks for it's presence, there might be a timing issue. In which case it may check that the dropdown is present in the DOM but is not actually opening the dropdown.
May want to try something like:
dropdown = b.link(:class => 'btn-open-filers')
dropdown.click if dropdown.visible?
b.select_list(:name => "bedroomsMin").select '3+ Beds'
Watir is designed to interact with the elements that a user can interact with. So if it isn't visible to a user, you shouldn't be able to interact with it. So, it's feature, not a bug. :)
That being said, it isn't clear from your post what action is causing the error. This code will wait for the select list to become visible before you try to select an option inside it:
b.link(class: 'btn-open-filers').when_present.click
b.div(class: 'form-group').wait_until_present
b.select_list(name: 'bedroomsMin").select '3+ Beds'
Justin's answer is functionally the same as this, and when_present is probably more elegant.

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.

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