8

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?

2 Answers 2

11

Try this:

WebDriver driver = new ChromeDriver();
((JavascriptExecutor)driver).executeScript("yourScript();");
Sign up to request clarification or add additional context in comments.

Comments

5
WebDriver driver = new AnyDriverYouWant();

if (driver instanceof JavascriptExecutor)

{

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

}

2 Comments

When you run this after loading a page in webdriver, this javascript is added to the page and it remains there until I reload the page. Is there a way to remove this javascript from the page after executing it only once?
I will need to check for that , will let you know solution when I get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.