1

Based on most of the answers i have seen, the solution here seems to be the way to go Wait for page load in Selenium . This makes sense, but it isn't working for me. I have a website written in Angular JS and i am trying to navigate through the a paginated list of results. Clicking the link to the next page just reloads a div and doesn't actually trigger a page load. The content on page 1 is different to page 2, but in terms of HTML, there isn't an element i can check for to know if the next page is up or not.

As a temporary fix, i have put a 3 second thread sleep into the navigation so that by the time the thread has woken up, phantomJS has rendered the new content. This is of course a bad fix since it usually takes less than a second, but cold potentially take a few seconds longer some day.

I was wondering if angular communicates with the dom in a way that allows phantomJS to read it and figure out the status?

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
Dan Hastings
  • 3,241
  • 7
  • 34
  • 71
  • 1
    Is there a reason why you are not using Protractor? Also is this question regarding AngularJS (1x) or Angular (2/4)? – Andy Kong Jun 20 '17 at 13:12
  • im using a custom built tool that is used for many websites, all of which are not angularJS. This is the first one and the tool isn't working for it so i need to make some accommodations to support the page loading when the site is angular – Dan Hastings Jun 20 '17 at 13:14
  • 1
    This may not be of much help, but here's Protractor's implementation of waitForAngular. https://github.com/angular/protractor/blob/3d98a1668138d36681bf305c9ea67dd1eea38899/lib/clientsidescripts.js#L135 If you're testing in using a non-SeleniumJS driver, an explicit sleep might be the best course of action for the time being in my opinion. – Andy Kong Jun 20 '17 at 13:25

1 Answers1

0

Usually when tags get refreshed they became stale. You can wait for the <div> tag to become stale using ExpectedConditions

IWebElement div = driver.FindElement(div locator); // locate the refreshing <div>
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.StalenessOf(div));

And now you need to check that there are items after the previous list was deleted

wait.Until(d =>
{
    ReadOnlyCollection<IWebElement> items = d.FindElements(items locator);  // locate the items list
    return items.Count > 0;
});
Guy
  • 46,488
  • 10
  • 44
  • 88