最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript test : Selenium cookies data url - Stack Overflow

programmeradmin3浏览0评论

I have a Behat test running Selenium whenever Javascript is needed. My current Behat test works just fine if Javascript (so Selenium is disable).

At the moment, my only error feedback from Selenium is the following statement :

unknown: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.
        (Session info: chrome=48.0.2564.109)
        (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.2.0-16-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 7 milliseconds
      Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
      System info: host: 'ca7a41afbfee', ip: '172.17.0.10', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-16-generic', java.version: '1.8.0_45-internal'
      Driver info: org.openqa.selenium.chrome.ChromeDriver
      Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/tmp/.google.Chrome.WWmJvH}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.109, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
      Session ID: b8a3f435fe337ca77d523d5b72f6235b (WebDriver\Exception\UnknownError)

What am I doing wrong here ? Some posts talk about cookies but I don't really see where to append them.

I have a Behat test running Selenium whenever Javascript is needed. My current Behat test works just fine if Javascript (so Selenium is disable).

At the moment, my only error feedback from Selenium is the following statement :

unknown: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.
        (Session info: chrome=48.0.2564.109)
        (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.2.0-16-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 7 milliseconds
      Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
      System info: host: 'ca7a41afbfee', ip: '172.17.0.10', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-16-generic', java.version: '1.8.0_45-internal'
      Driver info: org.openqa.selenium.chrome.ChromeDriver
      Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/tmp/..google.Chrome.WWmJvH}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.109, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
      Session ID: b8a3f435fe337ca77d523d5b72f6235b (WebDriver\Exception\UnknownError)

What am I doing wrong here ? Some posts talk about cookies but I don't really see where to append them.

Share Improve this question asked Mar 23, 2016 at 9:42 Benjamin RobertBenjamin Robert 811 silver badge5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

You can't set a cookie using the Chrome driver until the page is fully loaded. Use selenium to wait for the page to load and then set cookies.

You will need open page before add cookie:

$capabilities = DesiredCapabilities::chrome();
$host = 'http://localhost:4444/wd/hub'; // this is the default
$this->webDriver = RemoteWebDriver::create($host, $capabilities, 5000);
$this->urnOpen('/');
$cookie = array();
$cookie['name'] = 'NAME';
$cookie['value'] = 'VALUE';
$this->webDriver->manage()->addCookie($cookie);
发布评论

评论列表(0)

  1. 暂无评论