Skip to content

Commit 7d73ac1

Browse files
committed
Refactor add_css_link() and add_js_link() methods
1 parent bc62a3e commit 7d73ac1

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -710,24 +710,31 @@ def maximize_window(self):
710710
self.__demo_mode_pause_if_active()
711711

712712
def add_css_link(self, css_link):
713-
add_css_link_script = (
714-
'''var link = document.createElement("link"); '''
715-
'''link.rel = "stylesheet"; '''
716-
'''link.type = "text/css"; '''
717-
'''link.href = "%s"; '''
718-
'''link.crossorigin = "anonymous"; '''
719-
'''document.getElementsByTagName("head")[0]'''
720-
'''.appendChild(link);''')
721-
self.execute_script(add_css_link_script % css_link)
713+
script_to_add_css = (
714+
"""function injectCSS() {
715+
var head = document.getElementsByTagName("head")[0];
716+
var link = document.createElement("link");
717+
link.rel = "stylesheet";
718+
link.type = "text/css";
719+
link.href = "%s";
720+
link.crossorigin = "anonymous";
721+
head.appendChild(link);
722+
}
723+
injectCSS();""")
724+
self.execute_script(script_to_add_css % css_link)
722725

723726
def add_js_link(self, js_link):
724727
script_to_add_js = (
725-
'''var script = document.createElement("script"); '''
726-
'''script.src = "%s"; '''
727-
'''script.defer; '''
728-
'''script.crossorigin = "anonymous"; '''
729-
'''document.getElementsByTagName("head")[0]'''
730-
'''.appendChild(script);''')
728+
"""function injectJS() {
729+
var head = document.getElementsByTagName("head")[0];
730+
var script = document.createElement("script");
731+
script.src = "%s";
732+
script.defer;
733+
script.crossorigin = "anonymous";
734+
script.onload = function() {$("html")};
735+
head.appendChild(script);
736+
}
737+
injectJS();""")
731738
self.execute_script(script_to_add_js % js_link)
732739

733740
def add_css_style(self, css_style):

0 commit comments

Comments
 (0)