Radio Button not identified - ruby

I have tried a number of Ruby/Watir options to identify these two radio buttons and I can't do it. I want to .flash the radio button first then .set one of them.
browser.radio(:name => "appchoice_apps", :text => "Supervisor Console").flash
browser.radio(:span => "appchoice_supervisor").flash
I am not sure what else to try. I am very new here and I apologize for burning up your time.
<span id="appchoice_supervisor" style="visibility: visible;">
<input type="radio" name="appchoice_apps"></input>
Supervisor Console
</span>
<span id="appchoice_oa" style="display: block;">
<input type="radio" checked="" name="appchoice_apps"><input>
Associate Desktop
<br></br>
</span>

Solution 1 - By Text
The first example will not work because the text "Supervisor Console" is a sibling of the radio button rather than a text of the radio button.
browser.radio(:name => "appchoice_apps", :text => "Supervisor Console").flash
To check the sibling text, you can try getting the span by its text and then navigating to the radio button:
browser.span(:text => "Supervisor Console").radio.flash
Solution 2 - By Parent ID
The second example will not work because span is not a valid identifier.
browser.radio(:span => "appchoice_supervisor").flash
Like the first solution, you can locate the span by its id and then look for a radio button within that span:
browser.span(:id => "appchoice_supervisor").radio.flash

Related

Trying to select radio button with Watir

I am trying to select a radio button which i have done on other pages but cant seem to get this one to work
Here is the html for the radio button I am trying to access:
<fieldset id="category_fieldset">
<div class="group category first">
<label class="label"></label>
<div id="category_options">
<div class="toggle-btn">
<input id="category_rental" type="radio" value="rental" name="fields[category]"></input>
<label for="category_rental">
<span></span>
For Rent
</label>
Here are the --- i have made (none of these have worked)
browser.radio(:name => "fields[category]").set
browser.radio(:id => "category_rental").click
browser.radio(:value => "rental").click
thanks for the feedback on this
i tried this and seems to work
browser.label(:text => "For Rent").click

How to select a Radio button in Watir with label text?

The cheatsheets and docs on Watir show something like this to set a radio button
b.radio(:id => "radio").set
How can I select a Radio button based on the text next to it?
Sometimes this text is inside the label tag , sometimes its just inside some div/form tag. How do we handle this in Watir??
(Label texts in CAPS in below examples)
Example 1:
<form action="">
<input type="radio" value="male" name="sex"/>
MALE
<br/>
<input type="radio" value="female" name="sex"/>
FEMALE
</form>
Example 2 :
<div class="isoversixteen_false_container">
<input id="isoversixteen_false" class="radio" type="radio" value="0" name="isoversixteen" autocomplete="off"/>
<label class="isoversixteen_false_label" for="isoversixteen_false">
<span class="label_main">UNDER 16</span>
</label>
</div>
<div class="isoversixteen_true_container">
<input id="isoversixteen_true" class="radio" type="radio" value="1" name="isoversixteen" autocomplete="off" checked="checked"/>
<label class="isoversixteen_true_label" for="isoversixteen_true">
<span class="label_main">16 OR OVER</span>
</label>
</div>
Orde's comment about using attributes of the input element is a good idea as it is the easiest to program. However, to answer the question:
Example 1 - Adjacent text node
In this example, the desired text is in an adjacent text node. Given that the radio buttons share the same parent, I think the easiest solution would be to use XPath:
browser.radio(xpath: '//input[following-sibling::text()[1][normalize-space(.) = "MALE"]]').set
browser.radio(xpath: '//input[following-sibling::text()[1][normalize-space(.) = "FEMALE"]]').set
The XPath says to:
Find an input element where
The following text node - ie the [1]
Has the text "MALE" or "FEMALE", ignoring the leading/following spaces - ie the [normalize-space(.) = "FEMALE"]
Example 2 - Label text
In this example, the checkboxes have a properly associated label element - ie the id of the checkbox matches the for attribute of the label. Watir supports locating elements by their label text through the :label locator:
browser.radio(label: 'UNDER 16').set
browser.radio(label: '16 OR OVER').set
Example - First following non-blank text node
If you want a single solution that works with both examples, the following seems to work:
browser.radio(xpath: '//input[following::text()[normalize-space(.) != ""][1][normalize-space(.) = "UNDER 16"]]').set
browser.radio(xpath: '//input[following::text()[normalize-space(.) != ""][1][normalize-space(.) = "16 OR OVER"]]').set
browser.radio(xpath: '//input[following::text()[normalize-space(.) != ""][1][normalize-space(.) = "MALE"]]').set
browser.radio(xpath: '//input[following::text()[normalize-space(.) != ""][1][normalize-space(.) = "FEMALE"]]').set
The intent here is to find the first text node after the checkbox that has text (the [normalize-space(.) != ""][1] portion) and that text matches the expected text (the [normalize-space(.) = "UNDER 16" portion).
This is HTML structure I have in my example:
<div class="radio-inline">
<label for="job_type">Second Type</label>
<input id="job_service" name="job" type="radio" value="remote">
</div>
Normally I'd select it with:
#browser.input(:value => 'remote').click
However, per your question, I tried to see if I could select by text. I found this works, but may be dependent on the labels being nested in a div.
#browser.label(:text => /Second Type/).click
The / around "Second Type" were due to some weird line breaks in the HTML, may work with just quotes.

Using Watir-Webdriver to select radio button

I am trying to automate a survey and so far so good until I came to radio buttons which I assumed would be easy but I can't get them right.
The HTML code is this:
<span class="radioButtonHolder">
<span class="radioBranded" style="background-position: 0px -1px;"></span>
<input id="A.1" class="customCtrlLarge" type="radio" value="1" name="A"></input>
With Watir-Webdriver I tried:
browser.radio(:name => 'A', :value => '1').click
This hasn't worked. I have also tried:
browser.radio(:id => 'A.1').click
browser.find_element(:name => 'A', :value => '1').click
I've run into a similar problems on the site I test, in order for the front-end developer to 'stylize' the radio buttons he 'covers' them with a 'span' element. Making the 'actual' radio element unclickable. To get around this I 'click' on the 'span' element, which sets the radio selection.
I'm assuming you already tried to 'set' the radio button?
browser.radio(:name => 'A', :value => '1').set

Kendo Unbind ViewModel and rebind to other

I have viewmodel that i use for 'add' form. On that form i have 1 textbox called 'description'.
First time user enter some text in that field. Whan user press cancel( on the same form ) and then press Add again the form appearing with entered value in the 'description' field.
I want to create new view model and unbind all model with wrong value. But when i do that:
kendo.unbind($("#notes-dialog"));
kendo.bind($("#notes-dialog"), notesWindowModel);
the old value persist in the description textbox.
EDIT:
notesWindowModel = kendo.observable(
{
text: '2'
});
kendo.bind($("#notes-dialog"), notesWindowModel);
var notesWindowModel2 = kendo.observable(
{
text: '4'
});
kendo.unbind($("#notes-dialog"));
kendo.bind($("#notes-dialog"), notesWindowModel2);
Why does my field equal 2?
If i add
notesWindowModel.set('text', 'aaaa');
at the end my value equals 'aaaa'. It means that element is binded to first model. What is wrong here?
I found the problem:
<div id="notes-dialog">
<div id="notes-dialog-window" data-role="window" data-width="410" data-height="510" data-actions="" data-modal="true" data-title="false" style="display: none;">
<div id="notes-new-item">
<div>
<h3>Notes</h3>
<div>
<span>Note</span> <span>Is Delay?</span><span><input data-bind="value: model.Entity.IsDelay" class='k-input notes-checkbox' type='checkbox' /></span>
</div>
<div>
<textarea class="k-input utility-analysis-textarea notes-textarea" data-bind="value: text"></textarea>
The problem was that i have kendo window inside that element and when i open that window first time it replaces HTML and binding was wrong.
Old thread but I've recently faced the same issue.
In my case I've just had to destroy all kendo elements:
kendo.destroy(document.body);

Read text value from span tag

I need to read text value from span tag inside a selected radio button using capyvara
I have a list of radio button followed by text and its count in brackets.
For eg: radiobutton with Thank You(82)
What I want is to read the selected radio button count 82 inside bracket.
I used following code..but it is not working
value=page.find(".cardFilterItemSelection[checked='checked'] + span.itemCount").text
and tried using Xpath but not getting anything
value=page.find(:xpath,"//input[#class = 'cardFilterItemSelection' and #checked = 'checked']/span[#class = 'itemCount']/text()")
How it is possible?
<label id="thankyou_label" for="thankyou_radio" class="itemName radio">
<input checked="checked" tagtype="Occasion" value="Thank You" id="thankyou_radio" name="occasionGroup" class="cardFilterItemSelection" type="radio">
<span class="occasion_display_name">
Thank You
</span>
<span class="itemCount">
(82)
</span>
</label>
<label id="spring_label" class="itemName radio" for="spring_radio">
<input id="spring_radio" class="cardFilterItemSelection" type="radio" name="occasionGroup" value="Spring" tagtype="Occasion">
<span class="occasion_display_name">
Spring
</span>
<span class="itemCount">
(0)
</span>
</label>
I think you were on the right track. But you should have query not for the text node contained by span, but for the span itself and use XPath axes
span = page.find(:xpath,"//input[#class = 'cardFilterItemSelection' and #checked = 'checked']/following-sibling::span[#class = 'itemCount']")
value = span.text
However I personally find css selectors more readable (unless you need to make complex query)
span = page.find(:css, 'input.cardFilterItemSelection[checked=checked] ~ span.itemCount')
value = span.text

Resources