问题描述
与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);
1楼
Sudhansu Choudhary
2
2015-07-31 08:36:54
尝试这个,
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();";
只需使用'
(单引号)而不是"
(双引号),因此您将不需要"\\"
。