WebDriverError:无法设置cookie javascript

WebDriverError:无法设置cookie javascript,javascript,cookies,protractor,Javascript,Cookies,Protractor,我试图在量角器中设置一个cookie,但它不允许我 以下是错误: WebDriverError: unable to set cookie (Session info: chrome=63.0.3239.132) (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64) at WebDriv

我试图在量角器中设置一个cookie,但它不允许我

以下是错误:

    WebDriverError: unable to set cookie
  (Session info: chrome=63.0.3239.132)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64)
    at WebDriverError (e:\node_modules\selenium-webdriver\lib\error.js:27:5)
    at Object.checkLegacyResponse (e:\node_modules\selenium-webdriver\lib\error.js:505:15)
    at parseHttpResponse (e:\node_modules\selenium-webdriver\lib\http.js:509:13)
    at doSend.then.response (e:\node_modules\selenium-webdriver\lib\http.js:440:13)
    at process._tickCallback (internal/process/next_tick.js:109:7)
下面是负责设置cookie的测试代码

beforeEach(function() {
        //Enable Angular synchonization
        protractor_1.browser.waitForAngularEnabled(true);
        //Disable animations
        protractor_1.browser.manage().addCookie({ name: 'disableAnimations', value: 'true' }, '/', '127.0.0.1');
    });

为什么我的测试代码无法设置cookie?

如果这是完整的代码-我只能建议您必须首先打开要为哪个域添加cookie的页面,如:

beforeEach(function () {
    protractor_1.browser.waitForAngularEnabled(true);
    browser.get('http://127.0.0.1:8080') // set your url here
    //Disable animations
    protractor_1.browser.manage().addCookie({
        name: 'disableAnimations',
        value: 'true'
    }, '/', '127.0.0.1');
});

Selenium只能为已打开的域页面设置cookies

@TamerHussien请随意投票并接受答案!感谢您的评论
Selenium只能为已打开的域页面设置cookies