开发者

How to call JS file through selenium

开发者 https://www.devze.com 2023-04-02 17:01 出处:网络
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

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

精彩评论

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