如何在Selenium中的open()之前创建cookie

时间:2011-06-15 12:51:23

标签: cookies selenium

此代码仅适用于* 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');

在* firefox中,* iexplore仅适用于此:

$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');

我可以在* firefox等中打开()(没有多余的open()调用)之前创建cookie吗?

1 个答案:

答案 0 :(得分:3)

这一切都取决于每次注入浏览器的内容。

您记录的第二种方式是我这样做以确保它适用于多个浏览器版本。我不认为你可以为每个浏览器做第一种方式。