@@ -307,14 +307,14 @@ def add_css_link(driver, css_link):
307
307
def add_js_link (driver , js_link ):
308
308
script_to_add_js = (
309
309
"""function injectJS(link) {
310
- var head = document.getElementsByTagName("head ")[0];
310
+ var body = document.getElementsByTagName("body ")[0];
311
311
var script = document.createElement("script");
312
312
script.src = link;
313
313
script.defer;
314
314
script.type="text/javascript";
315
315
script.crossorigin = "anonymous";
316
316
script.onload = function() { null };
317
- head .appendChild(script);
317
+ body .appendChild(script);
318
318
}
319
319
injectJS("%s");""" )
320
320
js_link = escape_quotes_if_needed (js_link )
@@ -341,12 +341,12 @@ def add_js_code_from_link(driver, js_link):
341
341
js_link = "http:" + js_link
342
342
js_code = requests .get (js_link ).text
343
343
add_js_code_script = (
344
- '''var h = document.getElementsByTagName('head ').item(0);'''
345
- '''var s = document.createElement("script");'''
346
- '''s .type = "text/javascript";'''
347
- '''s .onload = function() { null };'''
348
- '''s .appendChild(document.createTextNode("%s"));'''
349
- '''h .appendChild(s );''' )
344
+ '''var body = document.getElementsByTagName('body ').item(0);'''
345
+ '''var script = document.createElement("script");'''
346
+ '''script .type = "text/javascript";'''
347
+ '''script .onload = function() { null };'''
348
+ '''script .appendChild(document.createTextNode("%s"));'''
349
+ '''body .appendChild(script );''' )
350
350
js_code = js_code .replace ('\n ' , '' )
351
351
js_code = escape_quotes_if_needed (js_code )
352
352
driver .execute_script (add_js_code_script % js_code )
0 commit comments