Watin - IE DOM not updating after javascript

397 views Asked by At

I have some code which uses Watin to enter search details into a webpage and then click a Search button. However, the search results never seems to update in the DOM so the new elements are never found. IE shows the correct data returned but the html is still from the previous search page.

Why does this not work even if I manually wait for the javascript to load?

using (var browser = new IE("http://www.abebooks.co.uk/servlet/SearchEntry"))
{
    browser.TextField(Find.ById("an2")).Value = "joyce";
    browser.Image(Find.ById("findBook-advancedSearch")).Click();

    //Try looping until element disappears
    while (browser.Image(Find.ById("findBook-advancedSearch")).Exists)
    {
        Thread.Sleep(200);
    }
    //Never gets past here element still not found after sleep

    //Try manually waiting for data to load
    Thread.Sleep(10000);

    //Correct data is in IE bit DOM is not updated???
    string myHtml = browser.Body.Parent.OuterHtml;

    browser.Div(Find.ById("abe-content")).Div(Find.ById("main")).Div(Find.ById("topbar")).WaitUntilExists(10);
}

I've tried a While loop to check if the previous page element no longer exists and also manually sleep to wait for the page. Also there appears to be no frames.

1

There are 1 answers

0
ProgrammerV5 On

Not sure what you are trying to do here. This code works fine on the site:

        using (var browser = new IE("http://www.abebooks.co.uk/servlet/SearchEntry"))
        {
            browser.TextField(Find.ById("an2")).Value = "joyce";
            browser.Image(Find.ById("findBook-advancedSearch")).Click();
            browser.WaitForComplete();
            Div dd = browser.Div(Find.ById("topbar"));
            MessageBox.Show(dd.InnerHtml);
        }

But the most important thing here is that you need to understand how Watin works. You need to wait until a page finishes loading, you were doing something similar whith an image that was displayed WHILE the page was searching but that doesn't mean that the page finished loading the result. I replace that code of yours with .WaitForComplete and also when searching for the DIV's I couldn't understand what you were looking for exactly so I just assumed that you were looking for the DIV that has the id topbar.

Hope this helps.