Login.

    Use Selenium webdriver to login. USPS authenticates users
    in part by a key generated by complex, obfuscated client-side
    Javascript, which can't (easily) be replicated in Python.
    Invokes the webdriver once to perform login, then uses the
    resulting session cookies with a standard Python `requests`
    session.

def _login(session):
    """Login.

    Use Selenium webdriver to login. USPS authenticates users
    in part by a key generated by complex, obfuscated client-side
    Javascript, which can't (easily) be replicated in Python.
    Invokes the webdriver once to perform login, then uses the
    resulting session cookies with a standard Python `requests`
    session.
    """
    _LOGGER.debug("attempting login")
    session.cookies.clear()
    try:
        session.remove_expired_responses()
    except AttributeError:
        pass
    try:
        driver = _get_driver(session.auth.driver)
    except WebDriverException as exception:
        raise USPSError(str(exception))
    driver.get(LOGIN_URL)
    username = driver.find_element_by_name('username')
    username.send_keys(session.auth.username)
    password = driver.find_element_by_name('password')
    password.send_keys(session.auth.password)
    driver.find_element_by_id('btn-submit').click()
    try:
        WebDriverWait(driver, LOGIN_TIMEOUT).until(EC.title_is(WELCOME_TITLE))
    except TimeoutException:
        raise USPSError('login failed')
    for cookie in driver.get_cookies():
        session.cookies.set(name=cookie['name'], value=cookie['value'])
    _save_cookies(session.cookies, session.auth.cookie_path)