Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send cookies with selenium webdriver?

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.

like image 422
Vladimir Bosyi Avatar asked Apr 26 '12 19:04

Vladimir Bosyi


People also ask

Can Selenium handle cookies?

Selenium WebDriver provides multiple commands for handling the cookies in a website. These Selenium cookies APIs provide you the required mechanism for interacting and querying the cookies. In Selenium Java, these methods are a part of the org. openqa.

Where we can store cookies in Selenium?

When the code is executed, webdriver will store the cookie information using FileWriter Class to write streams of characters and BufferedWriter to write the text into a file named “Cookiefile. data“. The file stores cookie information – “Name, Value, Domain, Path”.


1 Answers

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'}) 
like image 170
Isaac Avatar answered Sep 28 '22 01:09

Isaac