How to send cookies with selenium webdriver?

Vladimir Bosyi picture Vladimir Bosyi · Apr 26, 2012 · Viewed 70.7k times · Source

Every time when I run my test first step is log in and than I get to desire page. If run this test often log in operation takes a lot of time.

How can I pass log in operation?

Using Chrome and Firefox drivers, java language.

Answer

Isaac picture Isaac · Apr 27, 2012

Create cookies using the Java API as follows:

Cookie ck = new Cookie("name", "value");
driver.manage().addCookie(ck);

Create cookies using the Python API as follows:

driver.add_cookie({'name': 'foo', 'value': 'bar'})