Using Kameleo with Selenium framework

  • Created

When you are working with Kameleo and Selenium:

  1. You will use Kameleo Local API to manage your virtual browser profiles and launch Kameleo's built-in browsers.
  2. You will use Selenium to drive the browser with the W3C protocol.

Automate any browsing activity with Selenium. We'll help with keeping your scripts undetected by the sites you're visiting so that they won't see automation tools in use. Let's see how.

Before reading this article, we recommend reading the Getting started with Kameleo Automation article.

Install Selenium

To work with the Selenium framework, you need to install its official library.

  • npm i selenium-webdriver
  • Install-Package Selenium.WebDriver -Version 4.1.0
  • pip install selenium

Connect Selenium to a Kameleo profile

  1. Follow this guide for starting a profile from your script. Once the profile is up and running, you can move on to the next step to control it with Selenium commands.
  2. You need to build a WebDriver instance and pass the profile's unique ID as a capability named kameleo:profileId. In the case of some Selenium client library implementations, you also have to set the browserName capability, but the value can be anything.
    • const { Builder } = require('selenium-webdriver');
      const builder = new Builder()
          browserName: 'Kameleo',
      const webdriver = await;
    • using OpenQA.Selenium;
      using OpenQA.Selenium.Chrome;
      using OpenQA.Selenium.Remote;
      var uri = new Uri($"http://localhost:{KameleoPort}/webdriver");
      var opts = new ChromeOptions();
      opts.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
      var webdriver = new RemoteWebDriver(uri, opts);
    • from selenium import webdriver
      options = webdriver.ChromeOptions()
      driver = webdriver.Remote(
  3. Then you can use any WebDriver command to drive the browser, for example:
    • await webdriver.get("");
    • webdriver.Navigate().GoToUrl("");
    • driver.get('')
  4. Make sure to stop the browser and save the profile to a .kameleo file, so you can load it later. It's also essential to remove the profile from Kameleo once you don't need it anymore. This way, you can keep your resource usage low.
    • await client.stopProfile(;
      await client.saveProfile(, { body: { path: `${__dirname}\\test.kameleo` } });
      await client.deleteProfile(;
    • await client.StopProfileAsync(profile.Id);
      await client.SaveProfileAsync(profile.Id, new SaveProfileRequest(
      await client.DeleteProfileAsync(profile.Id);
    • client.stop_profile(
      path = f'{os.path.dirname(os.path.realpath(__file__))}\\test.kameleo'
      result = client.save_profile(, body=SaveProfileRequest(path=path))

If you want to see the full example code, click any of the links below:

Was this article helpful?

0 out of 0 found this helpful