Skip to content

Web Automations and user profiles

The BotCity Web Framework, by default, generates a temporary directory (which is later erased) to be used as a profile directory, so with each execution, a new clean session of the browser starts, ensuring information such as cookies, passwords and stored certificates do not interfere with the executions.

However, in some cases, it is pertinent to use an existing profile to take advantage of an already logged-in system or even to reduce the risk of being blocked by bot detection systems.

Configuring the browser to use a specific profile

By default, browsers launched through BotCity's Framework web have a set of selected and chosen options as essential for RPA automations. However, you may need to customize these options, such as in this case, where we will define an existing profile to launch the browser.

We will define this configuration through the browser's options property by accessing it through the default_options. Thus, it is possible to define the path of the profile directory you want to use when starting the browser with the WebBot, passing this path to the user_data_dir variable.

Next, you will follow the steps to configure browsers Google, Firefox, and MSEdge to use an already existing profile in your WebBot navigations.

Google Chrome

To start the Chrome browser with an existing profile with the BotCity Web Framework is very simple. Just import the property default_options in your code and pass the profile path you want for the user_data_dir variable, as shown below:

from botcity.web import WebBot, Browser
from botcity.web.browsers.chrome import default_options

def main():
    # Instantiate the WebBot
    bot = WebBot()

    # Configure whether or not to run on headless mode
    bot.headless = False

    profile_path = "<your browser profile path>/"

    # Fetch the default options for my preferred browser
    # Pass in the headless, download_folder_path and user_data_dir
    # to be used when building the default_options
    def_options = default_options(
        headless=bot.headless,
        user_data_dir=profile_path  # Inform the profile path that wants to start the browser
    ) 
    # Update the options to use the customized Options.
    bot.options = def_options

    # Opens the browser on the BotCity website with an existing profile
    bot.browse("https://botcity.dev")

    ...
import dev.botcity.framework.bot.WebBot;
import dev.botcity.framework.web.browsers.Browser;

import dev.botcity.framework.web.browsers.ChromeConfig;


public void action(BotExecution botExecution) {
    try {

        String profilePath = "<your browser profile path>/";

        // Configure whether or not to run on headless mode
        setHeadless(false);

        // Fetch the default options for my preferred browser
        ChromeConfig chromeConfig = new ChromeConfig();
        ChromeOptions defOptions = (ChromeOptions) chromeConfig.defaultOptions(
                isHeadless(), // Setting headless mode (using default)
                profilePath // Inform the profile path that wants to start the browser
        ); 

        // Update the options to use the customized Option.
        setOptions(defOptions);

        // Opens the browser on the BotCity website with an existing profile
        browse("https://botcity.dev");
        ...

Tip

The default Chrome installation typically stores user profile information in a path similar to this:

C:\Users\<user>\AppData\Local\Google\Chrome\User Data\Profile 1"

Firefox

To start the Firefox browser with an existing profile with the BotCity Web Framework is very simple. Just import the property default_options in your code and pass the profile path you want for the user_data_dir variable, as shown below:

from botcity.web import WebBot, Browser
from botcity.web.browsers.firefox import default_options

def main():
    # Instantiate the WebBot.
    bot = WebBot()

    # Configure whether or not to run on headless mode.
    bot.headless = False

    profile_path = "<your browser profile path>/"

    # Fetch the default options for my preferred browser
    # Pass in the headless, download_folder_path and user_data_dir
    # to be used when building the default_options
    def_options = default_options(
        headless=bot.headless,
        user_data_dir=profile_path, # Inform the profile path that wants to start the browser
    ) 

    # Update the options to use the customized Options.
    bot.options = def_options

    # Opens the browser on the BotCity website with an existing profile
    bot.browse("https://botcity.dev")

    ...
import dev.botcity.framework.bot.WebBot;
import dev.botcity.framework.web.browsers.Browser;

import dev.botcity.framework.web.browsers.FirefoxConfig;


public void action(BotExecution botExecution) {
    try {

        String profilePath = "<your browser profile path>/";

        // Configure whether or not to run on headless mode
        setHeadless(false);

        // Fetch the default options for my preferred browser
        FirefoxConfig firefoxConfig = new FirefoxConfig();
        FirefoxOptions defOptions = (FirefoxOptions) firefoxConfig.defaultOptions(
                isHeadless(), // Setting headless mode (using default)
                profilePath // Inform the profile path that wants to start the browser
        ); 

        // Update the options to use the customized Options.
        setOptions(defOptions);

        // Opens the browser on the BotCity website with an existing profile
        browse("https://botcity.dev");

        ...

Tip

The default Firefox installation typically stores user profile information in a path similar to this:

C:\Users\<user>\AppData\Local\Mozilla\Firefox\Profiles\profile_1

Microsoft Edge (MSEdge)

To start the Edge browser with an existing profile with the BotCity Web Framework is very simple. Just import the property default_options in your code and pass the profile path you want for the user_data_dir variable, as shown below:

from botcity.web import WebBot, Browser
from botcity.web.browsers.edge import default_options

def main():
    # Instantiate the WebBot.
    bot = WebBot()

    # Configure whether or not to run on headless mode
    bot.headless = False

    profile_path = "<your browser profile path>/"

    # Fetch the default options for my preferred browser
    # Pass in the headless, download_folder_path and user_data_dir
    # to be used when building the default_options
    def_options = default_options(
        headless=bot.headless,
        user_data_dir=profile_path  # Inform the profile path that wants to start the browser
    ) 

    # Update the options to use the customized Options.
    bot.options = def_options

    # Opens the browser on the BotCity website with an existing profile
    bot.browse("https://botcity.dev")

    ...
import dev.botcity.framework.bot.WebBot;
import dev.botcity.framework.web.browsers.Browser;

import dev.botcity.framework.web.browsers.EdgeConfig;


public void action(BotExecution botExecution) {
    try {

        String profilePath = "<your browser profile path>/";

        // Configure whether or not to run on headless mode
        setHeadless(false);

        // Fetch the default options for my preferred browser
        EdgeConfig edgeConfig = new EdgeConfig();
        EdgeOptions defOptions = (EdgeOptions) edgeConfig.defaultOptions(
                isHeadless(), // Setting headless mode (using default)
                profilePath // Inform the profile path that wants to start the browser
        );

        // Update the options to use the customized Options
        setOptions(defOptions);

        // Opens the browser on the BotCity website with an existing profile
        browse("https://botcity.dev");

        ...

Tip

The default Edge installation typically stores user profile information in a path similar to this:

C:\Users\<user>\AppData\Local\Microsoft\Edge\User Data\Profile 1

If you want to define the default profile, just change the Profile 1 to Default.

With these instructions, you can configure BotCity Framework Web to use an existing profile on supported browsers, allowing the reuse of login sessions and improving the efficiency of your web automations.