Ripon Al Wasim
Ripon Al Wasim

Reputation: 37766

How to call external JavaScript in WebDriver using Java

I can execute JavaScript in WebDriver (using java) as below:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("some JS code here;");

I want to execute an external JS file. How can I execute external JavaScript (.js file) in WebDriver?

Upvotes: 1

Views: 1441

Answers (1)

JimEvans
JimEvans

Reputation: 27486

You should use the file I/O mechanisms provided by your language (Java in this case) to read the contents of the JavaScript file into a String variable. You can then use that string in conjunction with the JavascriptExecutor.

Upvotes: 3

Related Questions