如何使用Chrome驱动程序和所有现有的浏览器Cookie启动Selenium?

到目前为止,据我了解,Chrome驱动程序始终在没有任何存储的浏览器cookie的情况下启动。

我需要驱动程序从Chrome存储的所有cookie开始。

我想知道是否有任何方法可以使用已存储的cookie启动驱动程序?我在.net 4.5中使用C#。

回答:

是的,我们可以像调用Firefox配置文件一样通过调用保存的Chrome配置文件来做到这一点。以下是我之前做的一些步骤

在Java中,我们可以使用ChromeOptions和Chrome配置文件来实现。在chrome中,导航至chrome:// version

/,它将显示配置文件路径和可执行路径。

根据我的工作,配置文件路径为“ \Local\Google\Chrome\User Data\Profile3这是显示我chrome://version/在普通chrome浏览器中导航至时显示的内容”。在此配置文件中,我导航至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://codingdict.com");

根据我的理解,我除了将http://codingdict.com页显示为已登录外,但第一次没有登录。因此在驱动程序打开的chrome中使用chrome://

version /进行了交叉检查,配置文件路径显示为\ Local \ Google \ Chrome \ User Data \ Profile 3 \

Default。然后手动登录到该配置文件中,它本身是由网络驱动程序打开的,并通过关闭它来执行增益。

最后,页面显示为已登录。所以它可能是在Java中,希望它可以帮助您尝试使用C#。

以上是 如何使用Chrome驱动程序和所有现有的浏览器Cookie启动Selenium? 的全部内容, 来源链接: utcz.com/qa/421133.html

回到顶部