Google Chrome浏览器的配置文件问题 [英] Profile issues with google chrome

查看:423
本文介绍了Google Chrome浏览器的配置文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自动化脚本遇到问题.我正在登录脚本中的URL.当我手动执行此操作时,它将正常登录,但是当我使用自动化脚本时,它会要求提供邮件中可用的验证码.

我想,如果我将使用chrome默认配置文件进行登录,那么就不会出现此问题.但这并没有帮助我.

有人可以提出任何解决方案吗?

解决方案

众所周知,Webdriver始终以全新的默认配置文件开头.这就是它要求进行验证的原因,但手动执行时却不相同.为了避免这种情况,您可以指定用于Webdriver的chrome配置文件.

在Java中,我们可以使用ChromeOptions和Chrome个人资料来完成此操作.在chrome中,导航到chrome://version/,它将显示配置文件路径和可执行路径.

根据我的工作,在正常的chrome中导航至chrome://version/时,会显示\ Local \ Google \ Chrome \ User Data \ Profile 3.在此配置文件中,我导航至stackoverflow并保存了凭据.所以在下面的代码中使用

 Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\poi-3.12\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("prefs", prefs);
options.addArguments("user-data-dir=C:\\Users\\murali\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);

//WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com/");

据我了解,我不显示显示为已登录的stackoverflow.com页面.但是,这是我第一次未登录.因此在驱动程序打开的chrome中使用chrome://version/进行了交叉检查,显示了配置文件路径作为 \ Local \ Google \ Chrome \ User Data \ Profile 3 \ Default.然后手动在该配置文件中自行登录,该配置文件由webdriver打开,并通过关闭配置文件来执行获取.

最后,页面显示为已登录.所以它可能在Java中,希望对您有所帮助.

谢谢, 穆拉利

I am facing an issue with my automation script.I am logging into a URL in my script.When I do that manually it login normally but when I use automation script it asks for verification code which is available on my mail.

I thought if I will use the chrome default profile for login then this issue should not arise.But it didn't helped me out.

Can anyone suggest any solution ?

解决方案

As known, Webdriver always starts with fresh, default profile. That is the reason its asking for verification but not same when do manually. To avoid it, you can specify the chrome profile which is used manually to webdriver.

In Java, we can done it by using ChromeOptions and Chrome Profile. In chrome navigate to chrome://version/ It will display profile path and Executable path.

As per my working on this, \Local\Google\Chrome\User Data\Profile 3 is displaying when navigate to chrome://version/ in normal chrome. In this profile, i navigated to stackoverflow and saved credentials. So used below code

 Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\poi-3.12\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("prefs", prefs);
options.addArguments("user-data-dir=C:\\Users\\murali\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);

//WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com/");

As per my understanding, i excepted stackoverflow.com page displayed as logged in. but for first time, i am not logged in. so cross checked with chrome://version/ in chrome opened by driver, profile path is displayed as \Local\Google\Chrome\User Data\Profile 3\Default . then logged manually in that profile it self, which is opened by webdriver and executed gain by closing it.

Finally, page is displayed as logged in. So it may be in java, i hope it will helps you.

Thank You, Murali

这篇关于Google Chrome浏览器的配置文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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