How to check if a page has finished loading in RSelenium

Imagine that you click on an element with RSelenium

on a page and want to get results on the resulting page. How to check that the loaded page loads? I can insert Sys.sleep()

between page rendering and element click, but that seems like a very ugly and slow way to do things.

+3


source to share


3 answers


Install ImplicitWaitTimeout

and then find the element on the page. Of?remoteDriver



setImplicitWaitTimeout (milliseconds = 10000)

Set the time the driver should wait while searching for items. When searching for one item, the driver will poll the page until the item is present or time out, whichever comes first. When searching for multiple items, the driver must poll the page until at least one item is found, or timed out, after which it will return an empty list. If this method is never called, the driver will default to an implicit wait of 0ms.

+3


source


In the RSelenium reference manual ( http://cran.r-project.org/web/packages/RSelenium/RSelenium.pdf ) you will find the setTimeout () method for the remoteDriver class:

setTimeout (type = "page load", milliseconds = 10000)

Configure the amount of time that a certain type of operation can complete before they are interrupted and the time to wait | the error is returned to the client.

type: the type of operation to set the timeout. Valid values: "script" for script timeouts, "implicit" to change implicit wait timeouts and "page load" to set page load timeouts. Default "page load"

milliseconds: The time, in milliseconds, allowed to run time-limited commands. The default is 10000 milliseconds.



This seems to suggest that remDr $ setTimeout () after remDr $ navigate ("...") actually waited for the page to load, or would return a timeout error after 10 seconds.

+1


source


you can also try this code waiting for the browser to provide whether the page is loaded or not.

objExecutor = (JavascriptExecutor) objDriver;
if (!objExecutor.executeScript("return document.readyState").toString()
    .equalsIgnoreCase("complete")){
    Thread.sleep(1000);
}

      

You can just put it on your base page, so you don't have to write it down in every block. I've never tried it with any AJAX enabled sites, but it might help you and your script dependency go away as well.

0


source







All Articles