Selenium opens up chrome not signed into Chrome ac

2019-07-30 02:18发布

I have recently been working with Selenium WebDriver. I am also working specifically with chromedriver. Whenever I open up a new chrome window (driver.get(url)), Chrome starts up in a completely default state, instead of the state it would open up in if I just opened a new window from my dock (I am on a macbook running OS X Yosemite). Is there a way around this? Or is this just a set behavior?

1条回答
Fickle 薄情
2楼-- · 2019-07-30 02:35

You will get a default profile unless you specify which profile to use. To configure it so Selenium will use your normal profile, navigate to chrome://version in a new tab. Your profile path is shown, and you just enter it as a specified option, just removing the "/Default" from the end of your path if it is there. This is all explained in this page from Google, but here's also an example (this is a Windows path, but the same code would work for Mac--just change the path):

    System.out.println("Now opening Chrome in my profile");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("user-data-dir=C:/Users/[your user name]/AppData/Local/Google/Chrome/User Data");

    driver = new ChromeDriver(options);
    driver.get("http://www.google.com");
查看更多
登录 后发表回答