How to create a cookie before open () in Selenium

This code only works 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://example.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 only this works:

 $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 a cookie before open () (without redundantly calling open ()) in * firefox, etc.?

+7
source share
1 answer

It all depends on what is entered into the browser each time.

The second way you documented is how I do it to make sure that it works in multiple versions of the browser. I do not think that you can do this in the first way for each browser.

+3
source

All Articles