开发者

How to create cookie before open() in Selenium

开发者 https://www.devze.com 2023-03-12 23:36 出处:网络
This code works only in *googlechrome. $this->browserBot->setCommandLineFlags(\'commandLineFlags=--disable-web-security\');

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

精彩评论

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

关注公众号