1

How can I get chrome local db cookies by selenium in java?

I use following code to wait the document will be ready but local db cookies is empty

webDriverWait.until(webDriver ->
"complete".equals((JavascriptExecutor) webDriver.executeScript("return document.readyState")))


driver.get(url);

connection = DriverManager.getConnection("jdbc:sqlite:" + chromeCookieDirectory);
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("select * from cookies");

If I add Tread.sleep and wait enough of time after driver.get(url) I got a lot of cookies.

What is the best way to do it?

Maria Dorohin
  • 355
  • 4
  • 17
  • You left out the code that gets the cookies. What is it that you mean by "local db cookies"? – pcalkins Oct 03 '22 at 17:46
  • Chrome cookies local db - I updated the question – Maria Dorohin Oct 03 '22 at 19:48
  • looks like you're trying to load the sql DB. You don't need Selenium for that at all. If you are just checking the current page's cookies, use Selenium's getCookies() method. If you are trying to decrypt your local Chrome cookie DB see here: https://stackoverflow.com/questions/22532870/encrypted-cookies-in-chrome/38701402#38701402 I believe it's encrypted using your Chrome account PW (or Windows account PW?) with DPAPI under the hood on Windows machines, and on Linux I think the key is hard-coded to "peanuts". (But easier to just use Chrome itself to view or transfer your cookies!) – pcalkins Oct 03 '22 at 19:55

0 Answers0