我在 Eclipse 中,编写 Java GUI/脚本,运行无头 chromedriver,我在尝试在驱动程序中加载 html2canvas.js [1] [2]库时遇到问题,然后调用我在其上编写的函数浏览器中的库;我收到此代码的未定义错误:
String ss1ScriptLoc = "C:\\Users\\me\\Desktop\\resources\\html2canvas.min.js";
String ss2ScriptLoc = "C:\\Users\\me\\Desktop\\resources\\takeScreenShot.js";
je.executeScript(
"var headID1 = document.getElementsByTagName('head')[0]; "
+ "var newScript1 = document.createElement('script'); "
+ "newScript1.type = 'text/javascript'; "
+ "newScript1.src = '" + ss1ScriptLoc + "'; "
+ "headID1.appendChild(newScript1); "
+ "var headID2 = document.getElementsByTagName('head')[0]; "
+ "var newScript2 = document.createElement('script'); "
+ "newScript2.type = 'text/javascript'; "
+ "newScript2.src = '" + ss2ScriptLoc + "'; "
+ "headID2.appendChild(newScript2); "
+ "$(document).ready( function () { takeScreenShot(); });"
);
这会导致未定义函数“takeScreenShot();”的错误 我以为我已经在本地 .js 文件中定义了它。
Starting ChromeDriver 75.0.3770.140 (-refs/branch-heads/3770@{#1155}) on port 48415
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Aug 05, 2019 9:36:53 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
java.util.concurrent.ExecutionException: org.openqa.selenium.JavascriptException: javascript error: takeScreenShot is not defined
(Session info: headless chrome=75.0.3770.142)
Caused by: org.openqa.selenium.JavascriptException: javascript error: takeScreenShot is not defined
(Session info: headless chrome=75.0.3770.142)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: '', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
跃然一笑
largeQ
相关分类