MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / activate_jquery

Function activate_jquery

seleniumbase/fixtures/js_utils.py:198–232  ·  view source on GitHub ↗
(driver)

Source from the content-addressed store, hash-verified

196
197
198def activate_jquery(driver):
199 # If "jQuery is not defined" on a website, use this method to activate it.
200 # This method is needed because jQuery is not always defined on web sites.
201 with suppress(Exception):
202 # Let's first find out if jQuery is already defined.
203 execute_script(driver, "jQuery('html');")
204 # Since that command worked, jQuery is defined. Let's return.
205 return
206 # jQuery is not defined. It will be loaded in the next part.
207 jquery_js = constants.JQuery.MIN_JS
208 add_js_link(driver, jquery_js)
209 for x in range(36):
210 # jQuery needs a small amount of time to activate.
211 try:
212 execute_script(driver, "jQuery('html');")
213 return
214 except TypeError as e:
215 if (
216 (
217 shared_utils.is_cdp_swap_needed(driver)
218 or hasattr(driver, "_swap_driver")
219 )
220 and "cannot unpack non-iterable" in str(e)
221 ):
222 pass
223 else:
224 if x == 18:
225 add_js_link(driver, jquery_js)
226 time.sleep(0.1)
227 except Exception:
228 if x == 18:
229 add_js_link(driver, jquery_js)
230 time.sleep(0.1)
231 # Since jQuery still isn't activating, give up and raise an exception
232 raise_unable_to_load_jquery_exception(driver)
233
234
235def are_quotes_escaped(string):

Callers 4

safe_execute_scriptFunction · 0.85
highlight_with_js_2Function · 0.85
highlight_with_jquery_2Function · 0.85

Calls 4

execute_scriptFunction · 0.85
add_js_linkFunction · 0.85
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…