1

Is there a way I can run my JS file through selenium Web driver?

I'm given to disable and enable JS script in my firefox browser when my tests are running. Is it possible to do that?

Currently, I set preferences in firefox profile and launch the browser to disable javascript, it is possible to do at runtime?

Claire Nielsen
  • 1,881
  • 1
  • 14
  • 31
Bhavana
  • 95
  • 3
  • 5

1 Answers1

2

Why are you disabling the Javascript? You need to enable them in order to execute your own script. You want to use JavascriptExecutor. You can do something like below.

String fileContents = Files.toString(new File("c:\\fullpathtoyourJS\\test.js"), Charsets.UTF_8);
JavascriptExecutor js = (JavascriptExecutor)driver;         
js.executeScript(fileContents); 
nilesh
  • 14,131
  • 7
  • 65
  • 79