views:

682

answers:

3

Seems none of the code I've tried has any affect. My intention is to close any and all JavaScript prompts that may come up by hitting the "OK" button. Problem is, my script has no affect on the prompts that come up. In other words, it does nothing.

Here's what I have:

fx = FireWatir::Firefox.start(somepage)
fx.startClicker("OK")
fx.button(:id, "OK").click
fx.button(:id, "CONFIRM").click

The HTML:

<script type="text/javascript">
    alert("Alert!");
    window.confirm("Confirm?");
</script>

The text in the prompts can change, my intention is to hit OK regardless of what is inside the alert/confirm prompt.

PS: I'm running Ubuntu.

+1  A: 

Pop ups are black magic to me. Did you try the solutions from here?

I would also suggest posting your question at watir-general.

Željko Filipin
Using solution #3 worked for me in Željko second link above. I modified the startClicker method slightly to take a browser variable parameter, but this was the one that finally worked.
Derek Morrison
A: 

I think your fx.button(:id, "OK").click was waiting state changed.
But javascript dialog does not change state.
So your watir will be waiting forever.
If not like that,I do not know.

The action will not change state, never return it.
So it needs click no wait.
When I use watir(not firewatir), @ie.button(:id, 'OK').click_no_wait.
Then better wait 1~3 second for popup.
Then as you like.
And moreover if you want control msg-box(popup), need to AutoIT. --This is sample for wait msg-box and click ok for IE popup--

autoit=WIN32OLE.new('AutoItX3.Control')
autoit.WinWait('Windows Internet Explorer')
autoit.WinActive('Windows Internet Explorer')
autoit.ControlClick('Windows Internet Explorer','','OK')

It is possible that completely I don't understand what you mean. If so ignore this.

tknv
A: 

Check out /var/lib/gems/1.8/gems/firewatir-1.6.5/unittests/html/JavascriptClick.html (assuming that's where your firewatir gem is installed). I ran the test and it worked for me. Maybe reading the test will give you some insight into how startClicker is supposed to work.

cdwilson