1

The button on a page has the following code:

<a onclick="return ValidateAll();" id="btnSignin" tabindex="5" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnSignin", "", true, "Login", "", false, true))'>Sign In

my code: ie.button(:id,"btnSignin").click does not throw any error yet does not click the button

How to make the button click?

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
Chandiran
  • 11
  • 3

3 Answers3

2

My guess would be that you need to fire JavaScript event. To find out which event should be fired read How to find out which JavaScript events fired?

Without a lot of experimenting, this could work:

browswer.link(:id => "btnSignin").fire_event "onclick"
Community
  • 1
  • 1
Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
  • Unfortunately, the one that u have mentioned is not working. This the event that firebug recorded: mousedown clientX=1129, clientY=320 focus mouseup clientX=1129, clientY=320 click clientX=1129, clientY=320 DOMActivate mouseout clientX=1129, clientY=320 One of the developers said, its actually an asp control LLINKBUTTOn and the onclick handler is an event handler in code behind file protected void btnLogin_Click(object sender, EventArgs e) so no JS involved here on button click. Thanks for ur reply – Chandiran May 09 '11 at 16:03
  • 1
    ASP is server side stuff. I think your developer is confused between client side and server side.. at the point Watir gets involved we are all on the client side of things. The code you posted is very specifically calling Javascript, we can all see it right there. The first thing happening is that there's an event handler looking to execute the javascript ValidateAll() method.. are you perhaps getting some kind of validation error on the form, is there some other value that needs to be properly filled in that isn't getting recognized? we might need to see more of the page or the form. – Chuck van der Linden May 11 '11 at 18:31
  • i was unable to find the button by text, won't return anything. so had to fix like this @browser.buttons.each{|b| (b.fire_event "onclick"; break) if b.text=='Proceed to Checkout'} – territorial Mar 30 '17 at 23:55
1

Your button is a hyperlink, so try this: ie.link(:id, "btnSignin").click

John
  • 6,404
  • 14
  • 54
  • 106
1

Your code has a typo in it.

ie.button(:id,"btnSigin").click

Should be:

ie.button(:id,"btnSignin").click

juan2raid
  • 1,606
  • 1
  • 18
  • 29