Using execute_async_script in the Selenium WebDriver Using execute_async_script in the Selenium WebDriver selenium selenium

Using execute_async_script in the Selenium WebDriver


It sounds like you are using the remote control setup right now, yes? You should be able to instantiate a WebDriver instance from within that code, but you need to reference the WebDriver dlls. You will need to instantiate an instance of a browser driver object (ie: FirefoxDriver, InternetExplorerDriver, ChromeDriver, etc..) and then set your IWebDriver "driver" property equal to that instance. Then create an interface object named "js" (or whatever you'd like) as an IJavaScriptExecutor object and call the non-static method "ExecuteScript" or "ExecuteAsyncScript" (in your case).

My code below is in C#.NET (assuming you're using NUnit). You'll have to find the Python implementation since I don't know that language.

Class data members:

private IWebDriver driver;private StringBuilder verificationErrors;private string baseURL;

Code:

driver = new FirefoxDriver(new FirefoxProfile());baseURL = "http://???";  // replace "???" with website domainISelenium selenium = new WebDriverBackedSelenium(driver, baseURL);selenium.Start();IJavaScriptExecutor js = driver as IJavaScriptExecutor;js.ExecuteScript("$('#id').click();");  // assumes JQuery is used in pagejs.ExecuteAsyncScript(...);