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

问题描述

| 此代码仅适用于* 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()之前(没有多余的open()调用)创建cookie吗?     

解决方法

        这一切都取决于每次注入浏览器的内容。 您记录的第二种方法是我要执行的方法,以确保它可以在多个浏览器版本上工作。我不认为您可以为每种浏览器做第一种方法。