The below code is not working properly when given with Selenium. It throws this error SCRIPT5009: '$' is undefined
in IE 9. But when it is run in Web browser console after removing the "\\" sign it is working fine.
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);
Try this,
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();";
just use '
(single quotes) instead of "
(double quotes), therefore you wont be needing "\\"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.