Selenium Browser Automation

Browser automation is a feature which allows you to automate processes online. This can be as simple as a simple button click to complex automated login and registration systems.

The Incogniton browser automation uses the selenium webdriver. Next to this we also support Puppeteer automation.

Supported languages

At the moment only python is supported. The current implementation requires some additional settings to be set in python before launching a profile. Other languages like Java are on the roadmap.

Selenium with Incogniton

To communicate with the selenium integration of Incogniton, two ports can be set.
One is the general API port and the other one is the specific selenium hub port.
The default API port is 35000 and the default selenium port is 4444.
The port values can be changed with the following steps:

  • Go to C:\Users\%username%\incogniton
  • Open auth.json
  • Change seleniumPort and apiPort to the desired port numbers

 

Requirements

Python example

from selenium import webdriver
from ast import literal_eval
import requests

incogniton_profile_id = 'xxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
incogniton_url = 'http://127.0.0.1:35000/automation/launch/python/'+incogniton_profile_id

resp = requests.get(incogniton_url)
incomingJson = resp.json()

python_dict = literal_eval(incomingJson['dataDict'])
driver = webdriver.Remote(
			command_executor = incomingJson['url'] ,options=webdriver.ChromeOptions())

driver.get("https://www.incogniton.com")

Python example with POST

from selenium import webdriver
from selenium import webdriver
from ast import literal_eval
import requests

incogniton_profile_id = 'fc68c71d-4e3e-43ec-9cf6-2541d7cbe6ae'

try:
	stop_url = 'http://127.0.0.1:35000/profile/stop/'+incogniton_profile_id
	resp = requests.get(stop_url)
except:
	print("Failed to stop")

incogniton_url = 'http://127.0.0.1:35000/automation/launch/python/'


data = {"profileID": incogniton_profile_id ,"customArgs": "--disable-notifications"}
resp = requests.post(incogniton_url,data)
print(resp.json())

incomingJson = resp.json()
python_dict = literal_eval(incomingJson['dataDict'])
incomingUrl = incomingJson['url']
driver = webdriver.Remote(
			command_executor = incomingUrl,options=webdriver.ChromeOptions())

driver.get("https://www.incogniton.com")

Puppeteer with Incogniton

NodeJS example

const puppeteer = require('puppeteer')
var request = require("request")
var incognitonProfileID = 'xxxxx-xxxx-xxxx-xxxx-xxxxxxxx';
var url = "http://localhost:35000/automation/launch/puppeteer/" + incognitonProfileID;

function sleepFor(sleepDuration) {
  var now = new Date().getTime();
  while (new Date().getTime() < now + sleepDuration) {}
}

function actions(body) {
  sleepFor(3000); //Some time for the browser to actually start.

  const screenshot = 'screenshot.png'
  try {
    (async () => {
      const browserURL = body.puppeteerUrl;
      const browser = await puppeteer.connect({
        browserURL
      });
      const page = await browser.newPage()
      await page.goto('https://hotmail.com')
      await page.screenshot({
        path: screenshot
      })
      await browser.close()
      console.log('See screenshot: ' + screenshot)
    })()
  } catch (err) {
    console.error(err)
  }
}

request({
  url: url,
  json: true,
  headers: {
    'Content-Type': 'application/json'
  }
}, function (error, response, body) {

  if (!error && response.statusCode === 200) {
    actions(body)

  }
})

If you have any questions after reading this article please do not hesitate to contact our support department.

Powered by BetterDocs