views:

293

answers:

3

i have this page displaying statement every 2 second (using javascript), at the end of it there is a link which the user can click.

with IE it will click the link before javascript generated statement is completed. when i use Link.Click()

(with Firefox it will throw exception, which is fine with me)

is there a way to wait for javascript execution to complete before link gets clicked (IE)?

TIA

EDITED // the code, pretty simple seaching for link that startwith //"Continue seaching" in the browser then click

if (ln.Text.StartsWith("Continue searching", StringComparison.CurrentCultureIgnoreCase))
{
  ln.Click();
}

Thx

A: 

return false from the function "Link.Click" then the default behaviour will be disregarded.

Dani Cricco
thx for the reply,unfortunately the link.Click is successful if run using IE(Firefox will throw exception), while the javascript still executing and page is still scrolling has not shown the link yet.
Sendoh
A: 

If I understand correctly, the link is already loaded, but javascript will attach some events to it a little bit later, right? Could you just wait a little bit using Thread.Sleep(500)? Or maybe you can find out what is going on after execution of javascript code. You will have to find out how js on that page works, but maybe js is adding some sort of class or something similar to that link so you could wait in active loop with a little bit of Thread.Sleep until js do its job.

prostynick
thx,that's what im doing now currently, just wondering whether there is a neater way of doing this.(btw, no event attached to the link, just want to click the link after the javascript stopped executing not when it still executing)thx
Sendoh
Yeah, but maybe the page itself is attaching some kind of event or modifying the page DOM, so you could just wait for that to happened. That's exactly what WatiN do when its waiting for 'complete' or 'until something' - WatiN is actively waiting in `while` loop. See `TryFuncUntilTimeOut` class and `Try` method. You can event use that class for your own purposes.
prostynick
@prostynick: there is no such thing as Thread.Sleep in javascript
Sean Kinsey
is there a way to access javascript global variable from Watin?thx
Sendoh
Probably. Try `Eval` on your `IE` object (or frame). Unfortunately I never tried this before and can't confirm that.
prostynick
eval(object) works on IE but not Firefox lolthx
Sendoh
A: 

Did you try using ie.WaitUntilContainsText("my text"); ?

Shady M. Najib