-1

I'm facing an issue when trying to open a specific site using Selenium WebDriver in JavaScript with the Chrome browser. The code below creates the browser driver, but it doesn't open the site when I use setChromeOptions(options). If I remove this line, the site opens normally. It seems there is something wrong with the Chrome options configuration. Additionally, I'm using a for loop because I need the driver to open all 4 browser profiles.

code:

const { Builder, Browser, By } = require("selenium-webdriver");
const chrome = require('selenium-webdriver/chrome');

const DEFAULT_DIR = "user-data-dir=C:\\Users\\allan\\AppData\\Local\\Google\\Chrome\\User Data";
const PROFILES = ["profile-directory=Profile 3", "profile-directory=Profile 4", "profile-directory=Profile 5", "profile-directory=Profile 7"];            
                //GOMES = Profile 3     /       MODAS = Profile 4       /       ROCCO = Profile 5       /       STORE = Profile 7

async function run(){
    //for (let i = 0; i < PROFILES.length; i++){
        var options = new chrome.Options();
        options.addArguments("user-data-dir=C:\\Users\\allan\\AppData\\Local\\Google\\Chrome\\User Data");
        options.addArguments(PROFILES[1]);

        let navegador = await new Builder()
            .forBrowser(Browser.CHROME)
            //.setChromeOptions(options)
            .build();

        await navegador.get("https://sellercentral.amazon.com.br/home"); 
    //}
}

run();

The problematic line seems to be setChromeOptions(options). If I comment out this line, the browser opens the site correctly. Is there something wrong with the Chrome options I'm passing?

Any help is appreciated!

The loop is currently disabled as I am trying to resolve the configuration settings first.

Error: SessionNotCreatedError: session not created: Chrome failed to start: exited normally. (session not created: DevToolsActivePort file doesn't exist) (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

1 Answer 1

0

I don't recognize this format,

"profile-directory=Profile 3"

According to the docs, it should look like

options.addArguments("user-data-dir=/path/to/your/custom/profile");

To confirm this is the issue, you can comment out each .addArguments() line, one at a time and see if it loads. I'm assuming it will work with the second line commented out.

Sign up to request clarification or add additional context in comments.

6 Comments

I was researching how to open a specific profile and found something at this link: stackoverflow.com/questions/66160500/…. The code manages to open the correct browser, but it crashes.
Did you try the code and read the docs link I provided?
I tried, removed that line that mentions the profile, and put the whole directory in one line, but it opened a session as a guest, moreover, the class described in the documentation was giving an error, as if it didn't exist.
Right... that means that the profile line is what is causing the issue. You need to figure out what the correct syntax is for adding a profile and that's what I send you in the link. The link is the official documentation and should work, if you are using it correctly.
I looked into the documentation in more detail. From what I understand, that is a class used in Java. The error currently being displayed is: SessionNotCreatedError: session not created: Chrome failed to start: exited normally. (session not created: DevToolsActivePort file doesn't exist) (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.