While using Chrome browser with selenium, I encountered an issue related to browser profiles. Everything works smoothly when the correct binary path is provided, but if an incorrect path is given, it refuses to run.
The specific problem arises when the browser runs without picking up the profile settings or extensions. Instead, it launches as a completely new instance of the browser. What could be causing this behavior?
Below is a snippet of my code:
const { Options } = require('selenium-webdriver/chrome');
const { Builder } = require('selenium-webdriver');
async function createNewChromeProfile() {
const options = new Options();
options.setChromeBinaryPath('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome');
options.addArguments(`--user-data-dir=/Users/bfzli/Library/Application Support/Google/Chrome/Default`);
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
return driver;
}
async function main() {
const driver = await createNewChromeProfile();
await driver.get('https://google.com');
}
main();
I attempted to run the code without specifying the binary path, but unfortunately, it did not resolve the issue.