Reputation: 37766
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
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