此代码仅适用于 *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(没有多余的open()调用)吗?
最佳答案
这一切都取决于每次注入(inject)浏览器的内容。
您记录的第二种方法是我用来确保它在多个浏览器版本上运行的方法。我认为您不能对每个浏览器都使用第一种方法。
关于cookies - 如何在 Selenium 中的 open() 之前创建 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6357912/