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?
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.