Selenium automation example
Use this Python Selenium script to automate browser profiles in Multilogin. It starts a profile, connects Selenium to the running browser, opens a website, and stops the profile after 5 seconds.
➡️ Before you start, generate your Multilogin automation token and add it to the script along with your folder ID and profile ID. You'll also need the Multilogin desktop app running to launch the profile.
This Python example uses Selenium to start and control an existing Multilogin browser profile. It performs the following actions:
- Adds your automation token to the API endpoint.
- Start the profile defining Selenium as the selected automation type
- Retrieve the port used by the running profile
- Start a Selenium driver on localhost using the retrieved port
- Use the driver to manipulate browser actions
- Stop the profile in 5 seconds
To start automating, check these resources first: Getting started with automation scripting.
Also, you will need an automation token: How to get your Multilogin automation token.
This example covers browser-profile automation. For native Android app automation on cloud phones, use ADB or Appium instead.
Who can use this script?
- 👨💻 Account owners and team members
- 💰 Pro 10 and higher plans
Before you start
- Install the following Python libraries:
- requests
- selenium
- Insert your values into the below variables in the script:
Need the profile ID? You can copy it directly from the Multilogin interface. Learn how: How to copy profile IDs in Multilogin.
You need an existing browser profile before running this script.
Running the script
- Launch the app, as it makes profile launching possible
- By default, the script below works for Mimic. To use it for Stealthfox, replace
options=ChromiumOptions()withoptions=Options()in the following line:driver = webdriver.Remote(command_executor=f'{LOCALHOST}:{selenium_port}', options=ChromiumOptions()) - Run the
.pyfile with your automation code
Script example
import requests
import time
from selenium import webdriver
from selenium.webdriver.chromium.options import ChromiumOptions
from selenium.webdriver.firefox.options import Options
MLX_BASE = "https://api.multilogin.com"
MLX_LAUNCHER = "https://launcher.mlx.yt:45001/api/v1"
MLX_LAUNCHER_V2 = (
"https://launcher.mlx.yt:45001/api/v2" # recommended for launching profiles
)
LOCALHOST = "http://127.0.0.1"
HEADERS = {"Accept": "application/json", "Content-Type": "application/json"}
# TODO: Insert your token in the variable below
API_TOKEN = ""
# TODO: Insert the Folder ID and the Profile ID below
FOLDER_ID = ""
PROFILE_ID = ""
def start_profile() -> webdriver:
r = requests.get(
f"{MLX_LAUNCHER_V2}/profile/f/{FOLDER_ID}/p/{PROFILE_ID}/start?automation_type=selenium",
headers=HEADERS,
)
response = r.json()
if r.status_code != 200:
print(f"\nError while starting profile: {r.text}\n")
else:
print(f"\nProfile {PROFILE_ID} started.\n")
selenium_port = response["data"]["port"]
driver = webdriver.Remote(
command_executor=f"{LOCALHOST}:{selenium_port}", options=ChromiumOptions()
)
# For Stealthfox profiles use: options=Options()
# For Mimic profiles use: options=ChromiumOptions()
return driver
def stop_profile() -> None:
r = requests.get(f"{MLX_LAUNCHER}/profile/stop/p/{PROFILE_ID}", headers=HEADERS)
if r.status_code != 200:
print(f"\nError while stopping profile: {r.text}\n")
else:
print(f"\nProfile {PROFILE_ID} stopped.\n")
token = API_TOKEN
HEADERS.update({"Authorization": f"Bearer {token}"})
driver = start_profile()
driver.get("https://multilogin.com/")
time.sleep(5)
stop_profile()Check that the script worked
If the script runs successfully, Multilogin starts the browser profile, Selenium opens the Multilogin website, and the profile stops after five seconds.
Troubleshooting
Profile does not start
- Make sure the Multilogin desktop app is open
- Check the folder ID and profile ID
Selenium cannot connect
- Check that you use
ChromiumOptions()for Mimic orOptions()for Stealthfox
Script stops during sign-in
- Check that your API token is valid and hasn't expired.