如何在Selenium Webdriver中添加/执行外部js文件

时间:2020-02-04 07:53:09

标签: javascript selenium selenium-webdriver automation

我已经尝试过以下方法,但是却遭到Files.toString的打击

Thread.sleep(4000);
js.executeScript("window.scrollTo(0, document.body.scrollHeight)"); 

String fileContents = Files.toString(new File("C:\\Users\\jack\\Documents\\screenshot\\Screenshots\\remove.js"), Charsets.UTF_8);
//JavascriptExecutor js1 = (JavascriptExecutor)driver;         
//js1.executeScript(fileContents);

//JavascriptExecutor js1 = (JavascriptExecutor) driver;
// js1.executeScript("document.getElementsByTagName('head')[0].innerHTML += '<script src=\"<C:\\Users\\jagruti.pagar\\Documents\\screenshot\\Screenshots\\remove-popups.js>\" type=\"javascript\"></script>';");

String externalJS = Files.toString( new File("C:\\Users\\jack\\Documents\\screenshot\\Screenshots\\remove.js"), Charset.forName("utf-8"));
// Object ignore = ((JavascriptExecutor) driver).executeScript(externalJS);

0 个答案:

没有答案