开发者

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://e开发者_开发问答xample.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜