Lua*_*ana 7 selenium selenium-chromedriver selenium-webdriver
据我所知,到目前为止,Chrome驱动程序始终没有任何存储的浏览器cookie.
我需要驱动程序从Chrome存储的所有Cookie开始.
我想知道是否有办法用已经存储的cookie启动驱动程序?我正在使用C#和.net 4.5.
小智 13
是的,我们可以通过像firefox配置文件一样调用保存的chrome配置文件来实现.下面是我在回来之前注意到的步骤
在Java中,我们可以使用ChromeOptions和Chrome Profile完成它.在chrome中导航到chrome:// version /它将显示配置文件路径和可执行路径.
根据我的工作,当导航到chrome:// version/in normal chrome时,显示\ Local\Google\Chrome\User Data\Profile 3.在此配置文件中,我导航到stackoverflow并保存凭据.所以使用下面的代码
Map prefs = new HashMap(); prefs.put("binary","C:\ Program Files(x86)\ Google\Chrome\Application\chrome.exe");
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/");
Run Code Online (Sandbox Code Playgroud)
根据我的理解,我除了登录后显示的stackoverflow.com页面.但是第一次,我没有登录.所以交叉检查chrome://版本/在由驱动程序打开的chrome中,配置文件路径显示为\ Local\Google\Chrome \用户数据\配置文件3 \默认.然后手动在该配置文件中自动记录,由webdriver打开并通过关闭它来执行获取.
最后,页面显示为已登录.因此它可能在java中,我希望它可以帮助您尝试使用C#.