- ExecuteScript method
These two concepts are explained in details in this link. I would like people visiting to read this link first because this would give a fair understanding of how to use both these components in our forthcoming scripts.
E.g.- You can use the
executeScript method for scrolling down the page.
- ExcecuteAsyncScript method
ExecuteAsyncScript method. This method is also used to run JS commands but only those who methods that ‘finishes’ only when a callback is used – eg.
setTimeout or asynchronous XHR.
The function invoked with
executeAsyncScript takes a ‘done callback’ as the last argument, which must be called to signal that the script is done executing.
E.G- You can use the
executeAsyncScript method for setting the timeout
driver.execute_async_script ("window.setTimeout(arguments[arguments.length − 1], 800);");
You can read about the detailed difference between these two methods in this awesome link.
However, please note that
async in the name doesn’t mean that the methods described in the
ExecuteAsyncScript will run
async of the Selenium code. It is imperative to know that , both functions block the WebDriver control flow until they complete – either running off the end of the code for
executeScript or when calling the ‘done callback’ with