我使用以下代码在selenium中执行jquery。即使在更改了许多jquery min文件后,我也收到以下错误。
Error : SCRIPT1004: Expected ';'
代码:
String mouseOverScript1 = "var script = document.createElement('script');"
+"script.src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.js';"
+"script.type = 'text/javascript';"
+"document.getElementsByTagName('head')[0].appendChild(script);";
((JavascriptExecutor) driver).executeScript(mouseOverScript1);
String mouseOverScript2 = "var script = document.createElement('script');"
+"script.src ='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js';"
+"script.type = 'text/javascript';"
+"document.getElementsByTagName('head')[0].appendChild(script);";
((JavascriptExecutor) driver).executeScript(mouseOverScript2);
String mouseOverScript3 = "var script = document.createElement('script');"
+"script.src ='•http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.map';"
+"script.type = 'text/javascript';"
+"document.getElementsByTagName('head')[0].appendChild(script);";
((JavascriptExecutor) driver).executeScript(mouseOverScript3);
((JavascriptExecutor)driver).executeScript("$(\"#ctrlHeader_Image2\").hide();");
答案 0 :(得分:0)
您在第二行中丢失了分号(; )
String mouseOverScript1 = "var script = document.createElement('script');"
+"script.src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.js';"//semicolon missed here
+"script.type = 'text/javascript';"
+"document.getElementsByTagName('head')[0].appendChild(script);";
希望这会对你有所帮助。如果你遇到任何问题,请尽快回来
答案 1 :(得分:0)
是的,它有效。我用这个替换了第三个js文件。
String mouseOverScript3 = "var script = document.createElement('script');"
+"script.src ='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js';"
+"script.type = 'text/javascript';"
+"document.getElementsByTagName('head')[0].appendChild(script);";
((JavascriptExecutor) driver).executeScript(mouseOverScript3);