当前位置: 首页 > 面试题库 >

保存chrome cookie selenium

束涵涤
2023-03-14
问题内容

我正在寻找一种方法来保存chrome会话cookie,即使在程序关闭后也可以保留。我假设写入文件将是执行此操作的好方法,但是我对如何完成此操作感到困惑。我的最终目标是保存登录cookie,以便用户不必每次都执行登录。这是一些代码:

Dim driver = New Chrome.ChromeDriver()
driver.Navigate.GoToUrl("URL")
'click stuff and login here
Dim _cookies = driver.Manage().Cookies.AllCookies
'write cookies to file or save somehow

问题答案:

您需要在所需的用户个人资料下运行Chrome。默认情况下,Selenium
Web驱动程序将创建一个临时配置文件。如果您为其提供用户个人资料,则该个人资料将保留,并且如果未将Chrome设置为删除Cookie,则会创建通常会为用户创建Cookie的所有登录信息。

有关详细信息,请参见Selenium
chromedriver网站

Use custom profile (also called user data directory)
By default, ChromeDriver will create a new temporary profile for each session. At times you may want to set special preferences or just use a custom profile altogether. If the former, you can use the 'chrome.prefs' capability (described later below) to specify preferences that will be applied after Chrome starts. If the latter, you can use the user-data-dir Chrome command-line switch to tell Chrome which profile to use:

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

You can create your own custom profile by just running Chrome (on the command-line or through ChromeDriver) with the user-data-dir switch set to some new directory. If the path doesn't exist, Chrome will create a new profile in the specified location. You can then modify the profile settings as desired, and ChromeDriver can use the profile in the future. Open chrome://version in the browser to see what profile Chrome is using.


 类似资料:
  • 要保存图形,从File菜单选择Save。要用图形格式如TIFF保存,以便在其他应用中使用,则从File菜单选择Export。还可以从命令行中保存-用saveas命令,包括任何以其他格式保存图象的选项。

  • Logstash 早期有三个不同的 elasticsearch 插件。到 1.4.0 版本的时候,开发者彻底重写了 LogStash::Outputs::Elasticsearch 插件。从此,我们只需要用这一个插件,就能任意切换使用 Elasticsearch 集群支持的各种不同协议了。 配置示例 output { elasticsearch { host => "192

  • 图片保存 将需要的内容保存在独立的文件里便于之后的导出。(存储于 Web 所用格式 Alt + Shift + Ctrl + S) 如需保存独立图层则要把需要的图层拖到新建的透明背景的图层,或在图层上右键复制(Duplicate)图层选择地址为新文件即可。 图片与背景合并的切图方法如下 保存格式的选择 保存类型一:色彩丰富切无透明要求时保存为 JPG 格式并选用时候的品质(通常使用品质 80 )。

  • 接口说明 该接口已经废弃,请使用【单体化、标绘、压平 -> GEOJSON上传】接口 如果需要标识模型上某个位置信息,可以通过调用该接口,来记录标识的位置 可以设置的内容有名称、位置信息以及标注图标和字体颜色 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 API地址 POST /api/marker/1.0.0/add 是否需要登录 是 请求字段说明

  • 接口说明 保存角色 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 API地址 POST /permissions/api/team/role/v1.0.0/save 是否需要登录 是 请求字段说明 参数 类型 请求类型 是否必须 说明 token string header 是 当前登录用户的TOKEN roleName string formData

  • 接口说明 保存场景 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 API地址 POST /wish3dearth/api/scene/v1.0.0/saveScene 是否需要登录 是 请求字段说明 参数 类型 请求类型 是否必须 说明 token string header 是 当前登录用户的TOKEN sceneId string formData

  • 接口说明 保存角色 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 如开启https功能,请求地址的协议应改为https,如:https://www.example.com/wish3dearth/api/access/v1.0.0/getLicenseInfo API地址 POST /permissions/api/team/role/v1.0.0/s

  • 接口说明 保存场景 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 如开启https功能,请求地址的协议应改为https,如:https://www.example.com/wish3dearth/api/access/v1.0.0/getLicenseInfo API地址 POST /wish3dearth/api/scene/v1.0.0/saveS