2

I need a solution how to wait until the web page is fully loaded. And exactly after that, waiting no longer, I need to perform actions with a web page: get URL of loaded page, check cookie, click <a> elements so on

I use the following code before work with loaded page:

IWait<IWebDriver> wait=new WebDriverWait(drv, TimeSpan.FromSeconds(30.00));                
wait.Until(d => ((IJavaScriptExecutor)drv).ExecuteScript("return document.readyState").Equals("complete"));

But this code does not wait in 100% cases until full load of a page in Chrome, and does not work in Internet Explorer!

Could you please offer better solution

Thanks for an answer in advance!

1
  • May be I'm very late to the party, but I found the same problem, and I solved it by using a small extension, which just creates and adds an elements with a known id inside the window.onload function which is injected by the extension as a content script, and in the webdriverwait, we can wait for the presence of this element by id Commented Dec 30, 2020 at 7:45

1 Answer 1

1

document.readyState does not always return the actual status of page load completion. see if you can wait on a particular element on the page, perhaps which gets loaded last on the page.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your comment. I'm aware of such solution - for the situation when the structure of the page that will be loaded, is known. BUT the problem is that the structure of
the page that will be loaded is NOT KNOWN BEFOREHAND (I simulate user's click on the banner in which a number of advertised products is displayed, each particular time different ad).After the click on banner, the advertised product's page load. I need to somehow receive event 'window.onload' or 'document.ready', but currently I have no idea how to implement this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.