K
K
kos_dev2017-02-23 01:02:22
C++ / C#
kos_dev, 2017-02-23 01:02:22

How to launch a browser with cookies attached using Selenium WebDriver?

Hello, please tell me how to launch a browser with ready-made cookies that are stored on the disk? That is, I want Selenium to not just launch a pristine browser, but use the cookie file that I already have. And, if someone knows, is it possible to simulate driving with a mouse using this WebDriver?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SlavikF, 2017-02-23
@kos_dev

You can move the mouse, (for) press the buttons using the builder:

Actions builder = new Actions(driver);

builder.keyDown(Keys.CONTROL)
   .click(someElement)
   .moveByOffset( 10, 25 );
   .click(someOtherElement)
   .keyUp(Keys.CONTROL).build().perform();

I don't know if cookies can be loaded from disk,
I add them via code:
Cookie cookie1 = new Cookie("key1", "value1");
driver.manage().addCookie(cookie1);
Cookie cookie2 = new Cookie("key2", "value2");
driver.manage().addCookie(cookie2);

S
SergeiSmirnov, 2019-10-23
@SergeiSmirnov

And how can you change the Yandex control line in cookies, can you tell me? So that Yandex perceives the appeal not as from an empty account, but as if there is already a history of requests in the past?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question