title: Preserving cookies between sessions
body: <p>I need to make sure that a browser is trusted every time the session is when performing Selenium script in Node.js (If the browser is not trusted by the server it resets in MFA with SMSes which I would like to avoid).
  In Puppeteer it is simple by:</p>
  <pre><code>const browser = await puppeteer.launch({headless: false,
      userDataDir: &quot;./user_data&quot;});
  </code></pre>
  <p>I would love to stay with puppeteer because of that but I have a dropdown selector on the page accessible only by name or xpath and page and page.select requires CSS selector:-(.</p>
  <p>So I moved back to Selenium, but there I have this persistency problem:</p>
  <p>At the end of a session I have:</p>
  <pre><code>var allCokies = await driver.manage().getCookies();  fs.writeFile(&quot;/Users/matnikr/Documents/scrape/selenium/cookies.json&quot;,JSON.stringify(allCokies), function(err){
          if (err) {return console.log(err)}
          console.log('file saved');})
  </code></pre>
  <p>A the begining I have:</p>
  <pre><code>driver = await new Builder().forBrowser('chrome').build();
  var allCokies =  JSON.parse(fs.readFileSync(&quot;/Users/matnikr/Documents/angular\ code/Aliorscrape/selenium/cookies.json&quot;,&quot;utf8&quot;));
     for (var key in allCokies){
          await driver.manage().addCookie(allCokies[key])
      }
      await driver.get('https:*******/do/Login');
  </code></pre>
  <p>And every time it feels like &quot;incognito&quot; session is started. Browser is untrusted. Any help appreciated.</p>