Selenium Webdriver:如何获取当前页面中的所有cookie [英] Selenium Webdriver : How to get All cookies in the Current page

查看:1672
本文介绍了Selenium Webdriver:如何获取当前页面中的所有cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用带有Java的Chrome驱动程序获取当前页面中的所有cookie. 关闭浏览器并尝试使用旧的cookie打开新的浏览器后,请帮助我一次检索页面中的所有cookie.

Trying to get all cookies in the current page using Chrome driver with java . Please help me to retrieve all cookies in the page once after close browser and trying to open new browser with old cookies.

推荐答案

从所有域中获取Cookie 在自动化测试中,可能存在某些情况,我们必须验证网站的Cookie.

Getting cookies from all domains In automated tests there might be instances where we have to validate cookies of a website.

Webdriver具有简单而强大的API,可以检索当前页面域的Cookie.这是读取Cookie的示例代码:

Webdriver has simple and powerful API to retrieve cookies of current page domain. Here is the sample code to read cookies:

public Dictionary<string, string> GetAllPageCookies()
        {
            return _driver.Manage().Cookies.AllCookies.ToDictionary(cookie => cookie.Name, cookie => cookie.Value);
        }

这篇关于Selenium Webdriver:如何获取当前页面中的所有cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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