Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking a button with WATIR WebDriver

I have been struggling with this all morning and was hoping to get some assistance. I have this button on a webpage that pulls up a control panel that lets the user select which widgets to display. I'm trying to get this to fire using watir webdriver and firefox 9.0 but having no luck at all. I'm able to login to the site, get to the page that contains the button but just can't click the 'CHOOSE YOUR FEATURES' button.

<div class="personalizationButton">
  <span class="personalizationStatus"></span>
  &nbsp;
  <b class="widgetPanelLink neo-button button-white">
    <span>CHOOSE YOUR FEATURES</span>
  </b>
</div>`

I've been concentrating on using div class 'personalizationButton' but perhaps I need to point to that 'b class'? Just not sure how to format it. Here are some examples of what I have tried

$browser.div(:class, 'personalizationButton').when_present.click 
$browser.button(:text => 'CHOOSE YOUR FEATURES').click 
$browser.button(:div => 'personalizationButton').click 

etc, etc... just not sure I'm getting the format right. I watch it get to the page, I see the 'CHOOSE YOUR FEATURES' button on the page, but it never clicks it. Usually I get an error like this depending on which version was used:

unable to locate element, using {:text=>"CHOOSE YOUR FEATURES", :tag_name=>"button"}

This is the version I think should work, When I try it I get no errors but see nothing happen in the browser either:

$browser.div(:class => "personalizationButton").click
like image 536
Derek Avatar asked Apr 16 '12 16:04

Derek


1 Answers

I'm not seeing anything inherently clickable (with output) in the HTML. With the IRB output, it shows that it is finding the div, but there is no action when clicking it. The <b> element is just the "bold" style, so we shouldn't need to try that.

If you can access the span with text CHOOSE YOUR FEATURES, that should be your button.

$browser.span(:text => "CHOOSE YOUR FEATURES").click
like image 87
adam reed Avatar answered Sep 21 '22 02:09

adam reed