views:

403

answers:

3

Hey, this should be pretty simple, but it's causing me a lot of grief! I have lots of buttons like this:

<form class="general" method="post" action="/password">
  <div style="margin: 0pt; padding: 0pt; display: inline;">
    <input type="hidden" value="Yg4EweyWwXO8RAF9nd3RZKNmQw8Yk+f2vefLQ/IENyg=" name="authenticity_token"/>
  </div>
   <fieldset>
      <ol>
    </ol>
  </fieldset>
  <div class="submit save">
    <span class="submit">
      <input type="submit" value="Submit" name="commit"/>
    </span>
  </div>
</form>

so, the question is... how do I click the button?

I should point out that I am not using Webrat with selenium, just straight up selenium. I've tried "selenium.click"-ing just about everything I can think of. It seems that the click method want's an ID, but I don't know what ID to give it...

Any sugestions?

A: 
selenium.click("//input[@name='commit' and @value='#{button}']")

(told you it was simple)

Rodreegez
All the answers here are basically getting at the same thing. Thanks fot the responses, this is what I'm currently using in to test my app.
Rodreegez
+1  A: 

Try the following locator:

css=form.general input[type=submit]
Santi
+1  A: 

I might be missing some obvious reason why you can't use this but why not use:

name=commit
Dave Hunt
because there are several buttons on any given page.
Rodreegez
Okay. the other solutions will all click the first button though, so this would do the same and is arguably the simplest. If you want to click a specific button you could use something like `xpath=/descendant::input[@name='commit'][1]` where 1 is the index of the button you want to click.
Dave Hunt