如何使用selenium创建cookie?

发布于 2024-10-17 17:54:40 字数 119 浏览 1 评论 0原文

我想使用 selenium 创建一个 cookie。我见过一个支持此功能的方法,例如 selenium.createcookie(arg1,arg0),但我对传递的参数有点困惑。谁能给我举个例子吗?

I want to create a cookie using selenium. I have seen a method which supports this like selenium.createcookie(arg1,arg0), but I'm a bit confused about the arguments passed. Can anyone please give me an example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十年九夏 2024-10-24 17:54:40

创建Cookie(名称值对,选项字符串)
创建一个新的 cookie,其路径和域与当前测试页面的路径和域相同,除非您显式指定该 cookie 的路径。

参数:

  1. nameValuePair - 的名称和值
    格式为“name=value”的 cookie

  2. optionsString - 选项
    曲奇饼。目前支持的选项
    包括“路径”和“最大年龄”。这
    optionsString 的格式是
    “路径=/路径/,最大年龄=60”。订单
    选项无关紧要,单位
    'max_age' 的值是第二个。

来源: Selenium 参考

createCookie ( nameValuePair,optionsString )
Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.

Arguments:

  1. nameValuePair - name and value of
    the cookie in a format "name=value"

  2. optionsString - options for the
    cookie. Currently supported options
    include 'path' and 'max_age'. the
    optionsString's format is
    "path=/path/, max_age=60". The order
    of options are irrelevant, the unit
    of the value of 'max_age' is second.

source: Selenium reference

绾颜 2024-10-24 17:54:40
createCookie ( nameValuePair,optionsString )

创建一个新的 cookie,其路径和域与当前测试页面的路径和域相同,除非您显式指定该 cookie 的路径。

Arguments:

nameValuePair - name and value of the cookie in a format "name=value"
optionsString - options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.
createCookie ( nameValuePair,optionsString )

Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.

Arguments:

nameValuePair - name and value of the cookie in a format "name=value"
optionsString - options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.
勿忘初心 2024-10-24 17:54:40

使用 Firefox 访问您选择的网站(确实会创建 Cookie),然后转到“编辑”>“首选项”>“隐私”>“删除单个 Cookie”。单击其中一个 cookie。这将使您了解如何使用 createCookie 调用。我将选项“域”的术语切换为“主机”术语,效果很好。

Go on a site of your choice (that does create cookies) using firefox and go to Edit>Preferences>Privacy>Remove Individual Cookies. Click on one of the cookies. This will give you an idea of how to use the createCookie call. I switched the term of the option Domain the term by Host, which worked fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文