当前位置: 代码迷 >> JavaScript >> 在IE 9中通过Selenium(SCRIPT5009:'$'未定义)进行预期时,jQuery脚本无法正常运行,但在Web浏览器控制台中可以正常运行
  详细解决方案

在IE 9中通过Selenium(SCRIPT5009:'$'未定义)进行预期时,jQuery脚本无法正常运行,但在Web浏览器控制台中可以正常运行

热度:50   发布时间:2023-06-05 11:56:47.0

与Selenium一起使用时,以下代码无法正常工作。 它引发此错误SCRIPT5009: '$' is undefined在IE 9中SCRIPT5009: '$' is undefined 。但是,在删除“ \\”符号后在Web浏览器控制台中运行它时,它可以正常工作。

String scripts="var script=document.createElement('script');script.onload = function() {alert(\"Script loaded and ready\");};script.src = \"http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.js\";document.getElementsByTagName('head')[0].appendChild(script);$(\"*\").hide();";
((JavascriptExecutor) driver).executeScript(scripts);

尝试这个,

String scripts="var script=document.createElement('script');
  script.onload = function() {alert('Script loaded and ready');};
  script.src = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.js';
  document.getElementsByTagName('head')[0].appendChild(script);
   $('*').hide();";

只需使用' (单引号)而不是" (双引号),因此您将不需要"\\"

  相关解决方案