Web browser automation - Automating repetitive browsing tasks

Kameleo changes the browser fingerprint so you will be able to stay undetected. Why not automate your tasks in the browser with it? This makes possible to manage multiple online accounts automatically from one machine. We started the development of the browser automation and you can already try it out. We also provide a guide about a possible workaround with plugins. We are also waiting for your comments about it in email.

Browser automation in Kameleo

We are already developing the browser automation features of Kameleo. You won’t have to install any plugin to the browser, you will be able to write high-level automation code and Kameleo will do the work for you. We also plan to automate Kameleo’s operations, like creating a new profile automatically.

Right now it is possible to connect to the Selenium Driver after the browser is started by Kameleo. This way you can automate tasks in the browser by writing code in any language (For Example C#, Java, NodeJS, Python, Ruby, Perl, Javascript).

You simply have to enable External Selenium Connections in the App Settings.

Kameleo-Browser-Automation-Selenium-Connection.png

Then when you launch a desktop profile, the connection details will be printed by Kameleo.

Kameleo-Browser-Automation-Selenium-Port.png

Once the browser is running you can simply connect to the Selenium Driver from your code. Then you will be able to perform actions automatically in the browser. For example:

  • Automatically watch YouTube videos and comment
  • Automatically browse Facebook and like photos

Here we provide some examples.

NodeJS

const webdriver = require('selenium-webdriver')
const http= require('selenium-webdriver/http')

void async function() {
    // Replace with your session ID and selenium url
    let sessionId = '7144d6aedb9f3df591b65a1d52cf2f19';
    let url = 'http://localhost:54890';

    let driver = new webdriver.WebDriver(
        sessionId,
        new http.Executor(Promise.resolve(url)
            .then(
                url => new http.HttpClient(url, null, null))
        )
    );

    await driver.get('https://support.kameleo.io');
    await driver.findElement(webdriver.By.name('s')).sendKeys('automation');
    await driver.findElement(webdriver.By.id('searchsubmit')).click();
    let xPath = "//a[contains(text(),'Browser Automation')]";
    await driver.findElement(webdriver.By.xpath(xPath)).click();
}();

This script will open our knowledge base and search for automation articles and open the first one.

C#

using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace KameleoAutomationExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Replace with your session ID and selenium url
            var url = "http://localhost:53936";
            var sessionId = "208aa270ea366fdd4dd2d8baecc193b3";

            var uri = new Uri(url);
            AttachableRemoteWebDriver.SessionIdToAttach = sessionId; // This has to be done before the object instantiation
            var webDriver = new AttachableRemoteWebDriver(uri, new RemoteSessionSettings()); // You can instantiate with a specific driver options as well

            webDriver.Navigate().GoToUrl("https://support.kameleo.io/");
            webDriver.FindElement(By.XPath("//input[@id='searchsubmit']")).Click();
            webDriver.FindElement(By.XPath("//a[@rel='bookmark']")).Click();
        }
    }

    public class AttachableRemoteWebDriver : RemoteWebDriver
    {
        public static string SessionIdToAttach;

        public AttachableRemoteWebDriver(Uri remoteAddress, DriverOptions driverOptions)
            : base(remoteAddress, driverOptions)
        {
        }

        public AttachableRemoteWebDriver(Uri remoteAddress, RemoteSessionSettings remoteSessionSettings)
            : base(remoteAddress, remoteSessionSettings)
        {
        }

        protected override Response Execute(string driverCommandToExecute, Dictionary<string, object> parameters)
        {
            if (driverCommandToExecute == DriverCommand.NewSession)
            {
                return new Response
               {
                   SessionId = SessionIdToAttach
               };
            }
            else
            {
                return base.Execute(driverCommandToExecute, parameters);
            }
        }
    }
}

This script will open our knowledge base and open the first article in the search result.

Java

We haven’t created any automation code in Java yet. If you do please send us a code snippet in email and we will provide you a one-month free subscription. The code should open our knowledgebase and search for browser automation.

Python

We haven’t created any automation code in Python yet. If you do please send us a code snippet in email and we will provide you a one-month free subscription. The code should open our knowledgebase and search for browser automation.

Future developments

This selenium automation feature of Kameleo is requested by our community. We plan to build even more useful features for you. We would like to provide a solution where you can automate Kameleo itself as well. For example:

  • Automatically open a profile
  • Automatically create a profile
  • Automatically start a profile

Let us know if you have any comments about it in email (hello [at] kameleo [dot] io). We are also interested in your comments if you agree with our current plan. Also if you have further requests, comments, etc. We may like your idea and build this great software for your needs. Please provide as much information as possible.

One idea is to provide a REST interface where you can connect to Kameleo and create, save, load, clone, start, stop profiles automatically through it. You will be able to connect to the browser thru selenium as well.

The other idea is to let users import a well know script that will perform automatic operations in Kameleo like starting one or multiple profiles and navigating in the browser.

We will keep you updated about our plan. Please contact us in email if you have further comments on it.

Browser Automation with add-ons

A possible workaround to automatically perform operations in the browser with Kameleo is to install add-ons to the browser. Our recommendation is Kantu. It is available for Chrome and for Firefox.

You can simply install this add-on to the profile’s browser where you want to perform operations automatically.

With Kantu you can record what you do in the browser and it will generate code for you. You can edit and import the code any time and Kantu will perform everything automatically.

How to use Kantu

First, you will see an empty workspace in the table view and in the source view.

Kameleo-Browser-Automation-With-Kantu-1.png

If you click on the record button the program will start to write what you do in the browser.

Kameleo-Browser-Automation-With-Kantu-2b.png

You can see the generated code at the Source View. It is a JSON code, so you can edit the code if you do not like the record mode.

Kameleo-Browser-Automation-With-Kantu-3b.png

This example code will search our knowledgebase for articles about ‘proxy’ and open one of them.

{
"Name": "test",
"CreationDate": "1970-1-1",
"Commands": [
  {
    "Command": "clickAndWait",
    "Target": "link=Knowledgebase",
    "Value": ""
  },
  {
    "Command": "click",
    "Target": "xpath=//*[@id=\"searchform\"]/div/label",
    "Value": ""
  },
  {
    "Command": "type",
    "Target": "id=s",
    "Value": "proxy"
  },
  {
    "Command": "clickAndWait",
    "Target": "id=searchsubmit",
    "Value": ""
  },
  {
    "Command": "click",
    "Target": "link=Why is a proxy important?",
    "Value": ""
  }
]
}

After the code is done the browser can reproduce what is in the code. You have to click on the Play Macro button.

Kameleo-Browser-Automation-With-Kantu-4.png

Kantu can read and recognize images and text inside canvas elements, images, and videos. Kantu can resize the browser’s window.

Was this article helpful?
0 out of 0 found this helpful