I have: a persistent text cookie file I want: to set that cookie for Selenium requests
Code:
// go on the domain so we can set the cookie
driver.get("https://www.thedomain.com/404");
try {Thread.sleep(2000);} catch (Exception e) {}
    try{
       File file = new File('CookieFile.txt');
       FileReader fileReader = new FileReader(file);
       BufferedReader Buffreader = new BufferedReader(fileReader);
       String strline;
       while((strline=Buffreader.readLine())!=null){
            StringTokenizer token = new StringTokenizer(strline,";");
            while(token.hasMoreTokens()){
                 String name = token.nextToken();
                 String value = token.nextToken();
                 String domain = token.nextToken();
                 String path = token.nextToken();
                 Date expiry = null;
                 String val;
                 if(!(val=token.nextToken()).equals("null"))
                  {
                     expiry = new Date(val);
                  }
        Boolean isSecure = new Boolean(token.nextToken()).
                            booleanValue();
        Cookie ck = new Cookie(name,value,domain,path,expiry,isSecure);
        System.out.println(ck);
        driver.manage().addCookie(ck); // This will add the stored cookie to your current session
              }
          }
      }catch(Exception ex){
            ex.printStackTrace();
    }
Date String:
Mon Feb 15 15:38:00 CET 2021
Error by IDE:
java.lang.IllegalArgumentException
at java.util.Date.parse(Date.java:617)
at java.util.Date.(Date.java:274)
at MyClassName.testSaveCookie(MyClassName.java:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Writing/creating the cookie file works fine. It seems to have an issue with the Date object set. Any ideas?
 
     
    