Skip to main content

Selenium automation example

This guide walks you through a Python script that leverages the Selenium library to automate browser profile manipulation using the Indigo X API. The script performs the following actions:

  • Signs into Indigo X using the API.
  • Starts a browser profile with Selenium as the automation type.
  • Retrieves the port used by the running profile.
  • Initializes a Selenium WebDriver on localhost with the retrieved port.
  • Performs browser actions using the WebDriver.
  • Stops the profile after a brief delay.

By the end of this article, you'll have a working script to automate browser profiles and understand how to adapt it for different Indigo X browser types (Mimic or Stealthfox).


Prerequisites

Before running the script, ensure you have the following:

  1. Python Libraries: Install the required libraries using pip:

    pip install requests selenium
  2. Indigo X Account: You need a valid Indigo X account with:

    • USERNAME: Your Indigo X account email.
    • PASSWORD: Your Indigo X account password (MD5 encryption is not required).
    • FOLDER_ID and PROFILE_ID: Obtain these values using Indigo X's DevTools or Postman guides.
  3. Indigo X Agent: Ensure the Indigo X agent is connected, as it enables profile launching.


Script Overview

The Python script connects to the Indigo X API, starts a browser profile, and uses Selenium to manipulate it. Here's a breakdown of the key steps:

  1. Sign In: Authenticates with the Indigo X API to obtain a bearer token.
  2. Start Profile: Launches a browser profile with Selenium automation and retrieves the port.
  3. Selenium WebDriver: Initializes a WebDriver to interact with the browser on the specified port.
  4. Browser Actions: Performs actions like navigating to a website.
  5. Stop Profile: Closes the profile after a 5-second delay.

The script is compatible with Mimic and Stealthfox browser types, with a minor configuration change for Stealthfox.


Full Script

Below is the complete Python script. Replace the placeholder values (USERNAME, PASSWORD, FOLDER_ID, PROFILE_ID) with your own.

import requests
import hashlib
import time
from selenium import webdriver
from selenium.webdriver.chromium.options import ChromiumOptions
from selenium.webdriver.firefox.options import Options

# API Endpoints
INDIGO_BASE = "https://api.indigobrowser.com"
INDIGO_LAUNCHER = "https://launcher.indigobrowser.com:45011/api/v1"
INDIGO_LAUNCHER_V2 = "https://launcher.indigobrowser.com:45011/api/v2" # Recommended for launching profiles
LOCALHOST = "http://127.0.0.1"
HEADERS = {"Accept": "application/json", "Content-Type": "application/json"}

# Account Information (Replace with your values)
USERNAME = ""
PASSWORD = ""
FOLDER_ID = ""
PROFILE_ID = ""

def signin() -> str:
"""Authenticate with Indigo X and return a bearer token."""
payload = {
"email": USERNAME,
"password": hashlib.md5(PASSWORD.encode()).hexdigest(),
}
r = requests.post(f"{INDIGO_BASE}/user/signin", json=payload)
if r.status_code != 200:
print(f"\nError during login: {r.text}\n")
else:
response = r.json()["data"]
token = response["token"]
return token

def start_profile() -> webdriver:
"""Start a Indigo X profile and return a Selenium WebDriver."""
r = requests.get(
f"{INDIGO_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()
)
return driver

def stop_profile() -> None:
"""Stop the Indigo X profile."""
r = requests.get(f"{INDIGO_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")

# Execute the automation
token = signin()
HEADERS.update({"Authorization": f"Bearer {token}"})
driver = start_profile()
driver.get("https://indigobrowser.com/")
time.sleep(5)
stop_profile()

Configuring for Mimic vs. Stealthfox

The script defaults to the Mimic browser type, which uses ChromiumOptions. To use Stealthfox, modify the WebDriver initialization in the start_profile function:

driver = webdriver.Remote(
command_executor=f"{LOCALHOST}:{selenium_port}", options=ChromiumOptions()
)
Stealthfox Configuration

Ensure you import Options from selenium.webdriver.firefox.options when using Stealthfox.


Running the Script

Follow these steps to execute the script:

  1. Update Variables: Replace USERNAME, PASSWORD, FOLDER_ID, and PROFILE_ID with your Indigo X credentials and profile details.
  2. Ensure Agent Connection: Verify that the Indigo X agent is running and connected.
  3. Run the Script: Execute the .py file using Python:
    python your_script.py

The script will:

  • Sign into Indigo X.
  • Start the specified profile.
  • Open a browser and navigate to https://indigobrowser.com/.
  • Wait for 5 seconds.
  • Stop the profile.

Troubleshooting

If you encounter issues, check the following:

  • Agent Not Connected: Ensure the Indigo X agent is running.
  • Invalid Credentials: Verify your USERNAME and PASSWORD.
  • Incorrect IDs: Double-check FOLDER_ID and PROFILE_ID.
  • Port Conflicts: Ensure no other services are using the same port as the Indigo X profile.
Debugging Tips

The script includes error messages for login, profile start, and stop actions. Review the console output for details on any failures.