Selenium opens up chrome not signed into Chrome account

匆匆过客 提交于 2019-12-24 08:52:25

问题


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:


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");


来源:https://stackoverflow.com/questions/28420975/selenium-opens-up-chrome-not-signed-into-chrome-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!