Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if page finished loading in RSelenium

Imagine that you click on an element using RSelenium on a page and would like to retrieve the results from the resulting page. How does one check to make sure that the resulting page has loaded? I can insert Sys.sleep() in between processing the page and clicking the element but this seems like a very ugly and slow way to do things.

like image 375
Alex Avatar asked Nov 22 '14 18:11

Alex


People also ask

How do I know when a page has finished loading in Selenium?

We can get Selenium to recognize that a page is loaded. We can set the implicit wait for this purpose. It shall make the driver to wait for a specific amount of time for an element to be available after page loaded.

How will you wait until a Web page has been loaded completely?

We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method. We have to pass return document.

How Can You Tell Selenium is waiting?

Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs. Once the command is in place, Implicit Wait stays in place for the entire duration for which the browser is open.


2 Answers

Set ImplicitWaitTimeout and then search for an element on the page. From ?remoteDriver

setImplicitWaitTimeout(milliseconds = 10000)

Set the amount of time the driver should wait when searching for elements. When searching for a single element, the driver will poll the page until an element is found or the timeout expires, whichever occurs first. When searching for multiple elements, the driver should poll the page until at least one element is found or the timeout expires, at which point it will return an empty list. If this method is never called, the driver will default to an implicit wait of 0ms.

like image 89
jdharrison Avatar answered Sep 23 '22 02:09

jdharrison


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

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

Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client.

type: The type of operation to set the timeout for. Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout. Defaults to "page load"

milliseconds: The amount of time, in milliseconds, that time-limited commands are permitted to run. Defaults to 10000 milliseconds.

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

like image 22
Sam Gong Avatar answered Sep 23 '22 02:09

Sam Gong