Username and Password

For sites that lack two factor-authentication, the best way to manage login is by entering a username and password using a combination of Simplex’s type, click, press_tab, and press_enter actions.

This prevents needing to manage cookies or other login tokens that often expire after one-time use or need to be refreshed.

Saving Session Data

We never store your login data on our servers. The data gets deleted as soon as you close your session.

We provide the capture_login_session method to save a login session to a JSON file. This function returns a JSON containing the cookies and localStorage of the browser after being logged in.

Python
from simplex import Simplex

simplex = Simplex(api_key="your-api-key")
simplex.create_session(workflow_name="login_flow", proxies=False)
simplex.goto("https://www.simplex.sh/login-example.html")
simplex.press_tab() # tab into the username field
simplex.type("marco@simplex.sh")
simplex.press_tab() # tab into the password field
simplex.type("SuperSecretPassword123!")
simplex.press_enter()
simplex.wait(1000)
session_data = simplex.capture_login_session()
print(session_data)
simplex.close_session()

You should see the following output:

Two-Factor Authentication (2FA)

There are two ways to handle 2FA:

  1. Store your 2FA cookies in a session JSON using capture_login_session, then load the session JSON using Simplex’s create_session function.

2FA 'save cookies' option in the browser.

If you see a checkbox like the above in red when you login with 2FA, you can often check it then use the session JSON saved from that session to login directly.

When using this method, sometimes only the 2FA cookies are saved (and not the username/password cookies), and you’ll need to use Simplex’s actions to login with a username and password, then have the session cookies bypass the 2FA check.

  1. Disable 2FA for the site.

If you’re able to disable 2FA for the site, you can often just login with your username and password. This is the safest option, but it’s not always possible and is of course less secure.

Restoring Login Sessions

Login sessions can be restored using the session_data parameter in the constructor.

We show an example below. Let’s say you have a login session JSON for Coupa.com stored at sessions/coupa_login_session.json.

Sample Usage

from simplex import Simplex
simplex = Simplex(api_key="your_api_key")
simplex.create_session(session_data="sessions/coupa_login_session.json")
simplex.goto("https://supplier.coupahost.com/sessions/new")

Alternative ways to save session data

CLI tool

We provide a CLI tool to create login sessions. You can create a login session using simplex login [site] after installing the Simplex Python SDK.

simplex login https://simplex.sh/login-example.html

After you log in, you can click the button on the page to capture the login session. This will download a JSON containing your session data to wherever you ran the command from.

If you’d instead like to use the SDK, you can use the capture_login_session method.