Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

java - Cookies retrieve by a file in selenium web driver

I was trying to read the cookie which I saved through previous logged user.But I count get the result.showing error as "The constructor Boolean(String) is deprecated since version 9" and as follows,

Error _ga=GA1.2.323731428.1612457063; expires=Sat, 04 Feb 2023 10:14:24 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]:15473 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48' System info: host: 'DESKTOP-JJE0ILH', ip: '192.168.1.15', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.1' Driver info: driver.version: RemoteWebDriver

How can I fix this?

Code

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://demo.guru99.com/test/cookie/selenium_aut.php");                  
}   
}   
question from:https://stackoverflow.com/questions/66052613/cookies-retrieve-by-a-file-in-selenium-web-driver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...