How do I call a JavaScript function from Selenium?

I need to call a JavaScript function from Selenium WebDriver in Firefox. I use this command in the Firebug command editor to invoke the file upload application after logging into my site:

infoPanel.applicationManager.changeApp('FileUploader', {action: 'new'})

      

Is there a way to accomplish this from within Selenium?

+3


source to share


2 answers


WebDriver driver = new AnyDriverYouWant();

if (driver instanceof JavascriptExecutor)

{

((JavascriptExecutor)driver).executeScript("yourScript();");

}

      



+2


source


Try the following:



WebDriver driver = new ChromeDriver();
((JavascriptExecutor)driver).executeScript("yourScript();");

      

+5


source







All Articles