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)
| 290 | |
| 291 | |
| 292 | def 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 | |
| 316 | def remove_extra_slashes(selector): |
no test coverage detected