Skip to content

Web Automations and Extensions

In some cases, it is necessary to use browser extensions in order to proceed with the process.

In this guide, we will walk through the steps necessary to configure extensions in the browser we are using.

Using Extensions on Firefox

With the Firefox browser selected, we are able to easily add an extension using an .xpi file.

BotCity's Web Framework offers a specific method to install an extension in Firefox, all we need is the .xpi file referring to the extension.

...
# Import for the WebBot
from botcity.web import WebBot, Browser, By

bot = WebBot()

# Setting to use Firefox
bot.browser = Browser.FIREFOX

# Setting the path of the Firefox WebDriver
bot.driver_path = "<webdriver path>"

# Setting the extension path
extension_path = "<path to the .xpi file>"

# Adding the extension
bot.install_firefox_extension(extension=extension_path)

bot.browse(...)

...
...

// Setting to use Firefox
setBrowser(Browser.FIREFOX);

// Setting the path of the Firefox WebDriver
setDriverPath("<webdriver path>");

// Setting the extension path
String extensionPath = "<path to the .xpi file>";

// Adding the extension
installFirefoxExtension(extensionPath);

browse(...);

...

Tip

You can find extensions and download .xpi files on the Firefox Add-ons website.

Using Extensions on Chrome and Edge

For Chrome and Edge, instead of using a specific method we will add the extension via the browser's options.

As with Firefox, we will need a file that references the extension, in this case it will be a .crx file.

Warning

In some cases, Chrome and Edge may not be able to add an extension correctly.

This is a browser issue causing an exception when trying to load a specific extension.

To avoid such cases, it is recommended to use Firefox whenever possible.

...

# For Chrome
from botcity.web.browsers.chrome import default_options

# For Edge
# from botcity.web.browsers.edge import default_options

# Import for the WebBot
from botcity.web import WebBot, Browser, By

bot = WebBot()

# Setting to use Chrome
bot.browser = Browser.CHROME

# Setting the path of the Chrome WebDriver
bot.driver_path = "<webdriver path>"

# Setting the extension path
extension_path = "<path to the .crx file>"

# Using the default_options to add extensions
def_options = default_options()
def_options.add_extension(extension_path)
bot.options = def_options

bot.browse(...)

...
...

// For Chrome
import dev.botcity.framework.web.browsers.ChromeConfig;
import org.openqa.selenium.chrome.ChromeOptions;

// For Edge
// import dev.botcity.framework.web.browsers.EdgeConfig;
// import org.openqa.selenium.edge.EdgeOptions;

// Setting to use Chrome
setBrowser(Browser.CHROME);

// Setting the path of the Chrome WebDriver
setDriverPath("<webdriver path>");

// Setting the extension path
String extensionPath = "<path to the .crx file>";

// Using the defaultOptions to add extensions
ChromeConfig config = new ChromeConfig();
ChromeOptions options = (ChromeOptions) config.defaultOptions(isHeadless(), getDownloadPath(), null, PageLoadStrategy.NORMAL);
options.addExtensions(new File(extensionPath));
setOptions(options);

browse(...);

...