Selenium
Integrate Selenium WebDriver with Kameleo to automate browsing using realistic, spoofed browser fingerprints.
First create a profile, then choose how to start it:
- Auto-start: Skip
startProfile. When Selenium connects with thekameleo:profileIdcapability, Kameleo automatically starts the profile using defaults. - Explicit start: Call
startProfilebefore connecting. Use this when you need custom command-line switches, flags, or advanced options.
After either approach, you control the browser with normal Selenium commands, then clean up (stop / export / delete) the profile.
Prerequisites
- Completion of the Quickstart guide
- A Selenium-capable environment (Python, JavaScript, or C# with Selenium libraries installed)
Create a profile
from kameleo.local_api_client import KameleoLocalApiClient
from kameleo.local_api_client.models import CreateProfileRequest
from selenium import webdriver
client = KameleoLocalApiClient(endpoint='http://localhost:5050')
client.verify_engine_ready()
fps = client.fingerprint.search_fingerprints(device_type='desktop', browser_product='chrome')
profile = client.profile.create_profile(CreateProfileRequest(
fingerprint_id=fps[0].id,
name='selenium example'
))
import { KameleoLocalApiClient } from "@kameleo/local-api-client";
import { Builder } from "selenium-webdriver";
const client = new KameleoLocalApiClient({ basePath: "http://localhost:5050" });
await client.verifyEngineReady();
const fps = await client.fingerprint.searchFingerprints("desktop", undefined, "chrome");
const profile = await client.profile.createProfile({ fingerprintId: fps[0].id, name: "selenium example" });
using Kameleo.LocalApiClient;
using Kameleo.LocalApiClient.Model;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
var client = new KameleoLocalApiClient(new Uri("http://localhost:5050"));
await client.VerifyEngineReadyAsync();
var fps = await client.Fingerprint.SearchFingerprintsAsync(deviceType: "desktop", browserProduct: "chrome");
var profile = await client.Profile.CreateProfileAsync(new CreateProfileRequest(fps[0].Id) { Name = "selenium example" });
Option 1: Auto-start the profile (simpler)
Skip the explicit start call. Kameleo starts the profile automatically on the first WebDriver connection. Use this for quick scripts where default startup behavior is enough.
Connect Selenium WebDriver
Point Selenium to http://localhost:{port}/webdriver and supply kameleo:profileId.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.set_capability('kameleo:profileId', profile.id)
driver = webdriver.Remote(
command_executor='http://localhost:5050/webdriver',
options=options
)
import { Builder } from "selenium-webdriver";
const driver = await new Builder()
.usingServer("http://localhost:5050/webdriver")
.withCapabilities({ "kameleo:profileId": profile.id, browserName: "Kameleo" })
.build();
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
var remoteUri = new Uri("http://localhost:5050/webdriver");
var chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
var driver = new RemoteWebDriver(remoteUri, chromeOptions);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
Option 2: Explicitly start the profile (customizable)
Use this when you must set advanced startup parameters. The example below shows a start with some custom settings.
Start the profile (customization point)
Below are three common customization patterns. Pick one (or combine arguments + preferences) before connecting Selenium. The browser must be stopped and restarted to apply a different set.
- Add command-line arguments (e.g. mute audio)
- Pass extra Selenium options / capabilities (e.g. eager page load strategy)
- Set native browser preferences (e.g. disable images)
from kameleo.local_api_client.models import BrowserSettings, Preference
client.profile.start_profile(profile.id, BrowserSettings(
arguments=["--mute-audio"],
additional_options=[
Preference(key='pageLoadStrategy', value='eager'),
],
preferences=[
Preference(key='profile.managed_default_content_settings.images', value=2),
]
))
await client.profile.startProfile(profile.id, {
browserSettings: {
arguments: ["--mute-audio"],
additionalOptions: [{ key: "pageLoadStrategy", value: "eager" }],
preferences: [{ key: "profile.managed_default_content_settings.images", value: 2 }],
},
});
using Kameleo.LocalApiClient.Model;
await client.Profile.StartProfileAsync(profile.Id, new BrowserSettings(
arguments: new List<string> { "--mute-audio" },
additionalOptions: new List<Preference> {
new Preference("pageLoadStrategy", "eager"),
},
preferences: new List<Preference> {
new Preference("profile.managed_default_content_settings.images", 2),
}
));
Connect Selenium WebDriver
Point Selenium to http://localhost:{port}/webdriver and supply kameleo:profileId.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.set_capability('kameleo:profileId', profile.id)
driver = webdriver.Remote(
command_executor='http://localhost:5050/webdriver',
options=options
)
import { Builder } from "selenium-webdriver";
const driver = await new Builder()
.usingServer("http://localhost:5050/webdriver")
.withCapabilities({ "kameleo:profileId": profile.id, browserName: "Kameleo" })
.build();
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
var remoteUri = new Uri("http://localhost:5050/webdriver");
var chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
var driver = new RemoteWebDriver(remoteUri, chromeOptions);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
Run Selenium commands
driver.get('https://google.com')
await driver.get("https://google.com");
driver.Navigate().GoToUrl("https://google.com");
Finish the session
Always stop the profile to persist its state. Optionally export it for backup or delete it to reclaim space.
Stop, export, or delete
import os
from kameleo.local_api_client.models import ExportProfileRequest
driver.quit()
client.profile.stop_profile(profile.id)
export_path = f'{os.path.dirname(os.path.realpath(__file__))}/test.kameleo'
client.profile.export_profile(profile.id, body=ExportProfileRequest(path=export_path))
client.profile.delete_profile(profile.id)
await driver.quit();
await client.profile.stopProfile(profile.id);
await client.profile.exportProfile(profile.id, { body: { path: `${import.meta.dirname}/test.kameleo` } });
await client.profile.deleteProfile(profile.id);
using Kameleo.LocalApiClient.Model;
await client.Profile.StopProfileAsync(profile.Id);
await client.Profile.ExportProfileAsync(profile.Id, new ExportProfileRequest(Path.Combine(Environment.CurrentDirectory, "test.kameleo")));
await client.Profile.DeleteProfileAsync(profile.Id);