1

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
random
  • 9,774
  • 10
  • 66
  • 83
user3763753
  • 11
  • 1
  • 3
  • Your original attempt works for me. Can you explain what you mean by "hasn't worked"? What does Watir do? Is there an exception? – Justin Ko Jun 22 '14 at 00:35
  • I was looking at selenium IDE and when I click the radio buttons I get this: http://postimg.org/image/hmhm8m3gj/. Not sure how to post code in comments kinda new here. Um as when I say it doesn't work it doesn't seem to select the radio button. Not sure if the css even in the pic I posted has something to do with it or not. But I really do appreciate your help. – user3763753 Jun 22 '14 at 00:59
  • Also could it be perhaps that I am not waiting when moving from the first page to the second? These radio buttons are on the second page of a website so was thinking perhaps that could be the issue. Thanks again. – user3763753 Jun 22 '14 at 01:10
  • It is a bit hard to diagnose the problem without being able to reproduce it. The Selenium IDE does not seem to do any interaction with a radio button. As well, the lack of exception suggests that the radio button is being found (ie you are on the right page). Out of curiosity, do you get a different result if you use `.set` instead of `.click`? – Justin Ko Jun 22 '14 at 01:14
  • *** Also I was wrong before I am getting an error: 'assert exists' : unable to locate element, using {name=>"A", vlaue=>"1", :tag_name=>"button"} (Watir::Exception::UnknownObjectException) *** Sorry about not noticing it before kinda clunky having to go check terminal and having seleniium IDE + firefox open. – user3763753 Jun 22 '14 at 01:26
  • UPDATE: so I got the 'Next' button to work on the page and though my selection of the radio buttons does not raise any exceptions the page says I have yet to make any selections. I have been reading up and it might be that the buttons are nested in frames but I have tried everything in this thread: http://stackoverflow.com/questions/4792474/watir-radio-button-not-found – user3763753 Jun 22 '14 at 02:17
  • Hey Justin I think it is a similar problem to here: http://stackoverflow.com/questions/19574904/setting-radio-button-using-ruby-and-watir I tried .exists? .present? .visible? and I get true, false, false for the radio buttons in question... I think the css is hiding them somehow do you have any suggestions for me if that is ineed the case? – user3763753 Jun 22 '14 at 12:55
  • Did you try duplicating the steps that Selenium IDE does? The image you showed did not interact with the radio button mentioned, so perhaps there is a different control that you need to interact with (that then through Javascript sets the radio button). – Justin Ko Jun 23 '14 at 12:43

1 Answers1

2

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
Carldmitch
  • 409
  • 2
  • 5
  • I am not sure but I hope this works I am going to go experiment with your suggestion now. – user3763753 Jun 23 '14 at 20:46
  • Yup you were 100% rightbrowser.div(:id => 'FNSR00900').div(:class => 'Opt1 rbloption').span(:class => 'radioBranded').click browser.div(:id => 'FNSR60000').div(:class => 'Opt1 rbloption').span(:class => 'radioBranded').click browser.div(:id => 'FNSR39000').div(:class => 'Opt2 rbloption').span(:class => 'radioBranded').click browser.button(:id => 'NextButton').click – user3763753 Jun 23 '14 at 21:43