Find HTML elements using jQuery-style selectors.

    Ensures that jQuery is available to the browser; if it gets a
    WebDriverException that looks like jQuery is not available, it attempts to
    include it and reexecute the script.

def find_elements_by_jquery(browser, selector):
    """Find HTML elements using jQuery-style selectors.

    Ensures that jQuery is available to the browser; if it gets a
    WebDriverException that looks like jQuery is not available, it attempts to
    include it and reexecute the script."""
    try:
        return browser.execute_script("""return ($ || jQuery)(arguments[0]).get();""", selector)
    except WebDriverException as e:
        if e.msg.startswith(u'$ is not defined'):
            load_script(browser, "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js")
            return browser.execute_script("""return ($ || jQuery)(arguments[0]).get();""", selector)
        else:
            raise