MCPcopy Index your code
hub / github.com/seleniumbase/SeleniumBase / safe_execute_script

Function safe_execute_script

seleniumbase/fixtures/js_utils.py:292–313  ·  view source on GitHub ↗

When executing a script that contains a jQuery command, it's important that the jQuery library has been loaded first. This method will load jQuery if it wasn't already loaded.

(driver, script)

Source from the content-addressed store, hash-verified

290
291
292def safe_execute_script(driver, script):
293 """When executing a script that contains a jQuery command,
294 it's important that the jQuery library has been loaded first.
295 This method will load jQuery if it wasn't already loaded."""
296 try:
297 execute_script(driver, script)
298 except TypeError as e:
299 if (
300 (
301 shared_utils.is_cdp_swap_needed(driver)
302 or hasattr(driver, "_swap_driver")
303 )
304 and "cannot unpack non-iterable" in str(e)
305 ):
306 pass
307 else:
308 activate_jquery(driver) # It's a good thing we can define it here
309 execute_script(driver, script)
310 except Exception:
311 # The likely reason this fails is because: "jQuery is not defined"
312 activate_jquery(driver) # It's a good thing we can define it here
313 execute_script(driver, script)
314
315
316def remove_extra_slashes(selector):

Callers 2

highlight_with_jqueryFunction · 0.85
highlight_with_jquery_2Function · 0.85

Calls 2

execute_scriptFunction · 0.85
activate_jqueryFunction · 0.85

Tested by

no test coverage detected