def safe_execute_script ( driver , script ) : try : driver . execute_script ( script ) except Exception : # The likely reason this fails is because: "jQuery is not defined" activate_jquery ( driver ) # It's a good thing we can define it here driver . execute_script ( script )
run a python script jquery
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 .
def safe_execute_script(driver, script):
    """ 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. """
    try:
        driver.execute_script(script)
    except Exception:
        # The likely reason this fails is because: "jQuery is not defined"
        activate_jquery(driver)  # It's a good thing we can define it here
        driver.execute_script(script)