且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在 Selenium Webdriver 中设置 cookie

更新时间:2023-09-01 09:00:46

您在导航到站点之前创建了 cookie.如果您尝试在域 www.example.com 上创建 cookie,那么您需要导航到该域上的某个页面,创建 cookie,然后开始测试.

You are creating the cookie before navigating to the site. If you are trying to create a cookie on the domain www.example.com, then you would want to navigate to some page on that domain, create the cookie, and then start your test.

从我之前的阅读来看,***的方法是导航到某个您知道域中不存在的页面,例如www.example.com/this404page,然后创建 cookie.它应该加载得更快,因为它是一个错误页面并且不应该包含太多内容.在 404 页面上创建 cookie 后,开始测试.

From my reading a while back, the best way to do this is to navigate to some page you know will not exist on the domain, e.g. www.example.com/this404page, then create the cookie. It should load a lot faster since it's an error page and shouldn't contain much content. After creating the cookie on the 404 page, start your test.