简体   繁体   中英

How to call a JavaScript function from within Selenium?

I need to call a JavaScript function from Selenium WebDriver in Firefox. I use this command in Firebug's Command Editor to invoke a file upload application after logged into my website:

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

Is there a way to execute this from Selenium?

Try this:

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

if (driver instanceof JavascriptExecutor)

{

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM