Selenium打开未登录Chrome帐户的Chrome [英] Selenium opens up chrome not signed into Chrome account

查看:804
本文介绍了Selenium打开未登录Chrome帐户的Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在和Selenium WebDriver合作。我也正在专注于镀铬汽车。每当我打开一个新的chrome窗口(driver.get(url))时,Chrome会以完全默认的状态启动,而不是从我的dock中打开一个新窗口时打开的状态(我正在运行OS X Yosemite的Macbook)。有没有解决的办法?或者这只是一种行为?

解决方案

除非您指定使用哪个配置文件,否则您将获得默认配置文件。要配置它以便Selenium将使用您的正常配置文件,请在新选项卡中导航到 chrome://版本。显示您的配置文件路径,只需将其作为指定选项输入即可,只需从路径末尾删除/ Default(如果存在)即可。这些都在 Google的这个网页中解释过,但这里也是一个例子(这是一个Windows路径,但相同的代码可以在Mac上使用 - 只需更改路径):

  System.out .println(现在在我的个人资料中打开Chrome); 
ChromeOptions选项=新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);


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?

解决方案

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

这篇关于Selenium打开未登录Chrome帐户的Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆