开发者

How to call JS file through selenium

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?


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); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜