Problem in Selenium Browserstack session: loading existing Chrome profile

I am running a test with Selenium (Python) remotely on Browserstack Automate.

Goal: I want to start a session on Browserstack, with an existing Chrome profile logged in.

  • -- Underlying goal: I am trying to access Whatsapp Web without having to scan the QR code every single time. (Building an automated Whatsapp service)

So it would be ok to have a new profile made the first time - scan the QR code once and then re-use that profile afterwards.

Method: I try to use Chrome Options, and specify an argument for user-data-dir. This was inspired by several other StackOverflow answers.

Code:

desired_caps = {
    'browser': 'Chrome',
    'browser_version': '69.0 beta',
    'os': 'Windows',
    'os_version': '10',
    'resolution': '1024x768',
    'browserstack.debug': 'true',
}
desired_caps['browserstack.local'] = True
desired_caps['chromeOptions'] = {}       
desired_caps['chromeOptions']['args'] = [r'--user-data-dir=C:\Users\gille\AppData\Local\Google\Chrome\User Data']
driver = webdriver.Remote(command_executor='http://MYBROWSERSTACKHUB', desired_capabilities=desired_caps)

I am trying to run this on Browserstack (locally), but I am getting the following error when running:

"Could not initialize class org.openqa.selenium.os.Kernel32"

See image with Browserstack error

I have tried specifying a new random profile that did not exist yet, e.g.:

desired_caps['chromeOptions']['args'] = [r'--user-data-dir=C:\Users\gille\AppData\Local\Google\Chrome\User Data\ProfileXXX']

But the same error pops up.

(I have also tried other methods that did not work for me: - Saving and re-loading cookies - Changing the session_id and session_url (does not work on Browserstack) )

I feel that: - or this could be a problem with Browserstack, - or I am including the wrong path for user-data-dir, and should go with a different, e.g. chrome_options.add_argument("user-data-dir=" + os.path.dirname(sys.argv[0])

But I am unfamiliar with the last one - So I am unsure what the next step to take is. Do you have any advice?

1 answer

  • answered 2018-10-12 10:47 Kireeti Annamaraj

    Use the caps as below:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
    caps.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new RemoteWebDriver(new URL(CloudConfiguration.URL), caps);