How to create cookie before open() in Selenium
This code works only in *googlechrome.
$this->browserBot->setCommandLineFlags('commandLineFlags=--disable-web-security');
$this->browserBot->setBrowser('*googlechrome');
$this->browserBot->setHost('localhost');
$this->browserBot->setPort(4444);
$this->browserBot->setBrowserUrl('http://example.com');
$this->browserBot->start();
$this->browserBot->createCookie('foo=bar', 'path=/; domain=.example.com');
$this->browserBot->open('http://example.com/print_cookie.php');
In *firefox and *iexplore works only this:
$this->browserBot->start();
$this->browserBot->open('http://example.com/blank_page.html');
$this->browserBot->createCookie('foo=bar', 'path=/; domain=.example.com');
$this->browserBot->open('http://example.com/print_cookie.php');
Can I create cookie before open() (without redundant open() call) in *firefox and etc.?
This all depends on what is injected into the browser at each time.
The 2nd way that you documented is the way I would do it to make sure it worked over multiple browser versions. I don't think that you can do this the first way for every browser.
链接地址: http://www.djcxy.com/p/7804.html