'Multiple profiles open results into control of only one - selenium

I'm making an application that allows the user to automate a process they want in multiple chrome profiles at the same time, but whichever action I do on all (in this case) three profiles, only happens on one.

From my main script I'm connecting a module function that starts up selenium with the specified profile, now what happens is the following:

  1. All (in this case) three profiles launch chrome exactly as intended
  2. Now all three profiles should open google.com, but only one actually does it.

My main script:

        for (let i = 0; i < 10; i++) {

            let count = i == 0 ? "Default" : `Profile ${i}`

            let exists = fs.existsSync(`<checkdirectory>`)

            if (!exists) {
                maxamount = i
                break
            }

        }

        console.log(`Maxamount: ${maxamount}`)

        if (accamount > amount) accamount = amount

        if (accamount > maxamount) accamount = maxamount

        let extraleft = amount % accamount
        let accountper = (amount - extraleft) / accamount

        for (let i = 0; i < accamount; i++) {

            let currentper = accountper

            if (extraleft > 0) {

                currentper++
                extraleft--

            }

            ext.selhandler(id, currentper, i)

        }

And then the ext.selhandler() function is the following:

async function handlesel(asset, amount, account) {
    console.log(account)
    let options0 = new chromedriver.Options()

    let dirname = account == 0 ? `Default` : `Profile ${account}`
    console.log(dirname)
    options0.addArguments("user-data-dir=<the directory>")

    options0.addArguments(`profile-directory=${dirname}`)

    let b = await new Builder().forBrowser('chrome').setChromeOptions(options0).build()
    console.log(`${dirname} going to google`)
    await b.get("https://google.com/")
    console.log(`${dirname} went to google`)

}

(The directories are actually normal on my local, just replace for privacy reasons)



Solution 1:[1]

It seems I have discovered the answer to my question; When chromedriver runs a chrome instance, it locks the PARENT directory (by default the Chrome/User Data directory), in which normally the other profiles are located as well. The solution is to put all the profiles separately in different parent directories and then run each from their own parent directory, this way the rest doesn't get locked!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 April Summers