Profile issues with google chrome

橙三吉。 提交于 2019-12-01 13:32:02

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/36275652/profile-issues-with-google-chrome

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