Profile issues with google chrome

我的未来我决定 提交于 2019-12-01 15:29:00

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

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