0

This is the code which I am using for the retrieve the cookies while logging to the system. In this code shows error as "The constructor Boolean(String) is deprecated since version 9" and after running this code showed error as,

_ga=GA1.2.1160139618.1612543327; expires=Sun, 05 Feb 2023 10:12:08 IST; path=/; domain=.guru99.com org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:13686

How can I fix this?

public class CookieWrite        
{       

 
public static void main(String[] args){ 
    WebDriver driver;     
    System.setProperty("webdriver.chrome.driver","drivers\\chromedriver.exe");                  
    driver=new ChromeDriver();                  
try{            
 
    File file = new File("Cookies.data");                           
    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);   
            SimpleDateFormat sdf=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy"); 
            expiry = sdf.parse(val);
            //expiry = java.text.DateFormat.getDateInstance().parse(val);
            //System.out.println("t1");
        }       
        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();           
    }       
    driver.get("http://test.com/");                 
}   
}   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.