Selenium WebDriver????cookie
???????????? ???????[ 2014/10/9 13:56:57 ] ????????Selenium ??????? cookie
?????????webdriver?????У???????????????cookie???????????????????????????е????
??????????????Java Cookie????Щ??????
??????jsp?д???cookie???????÷?????
????getDomain??????????cookie??????.
????getMaxAge??????????cookie???????
????getName??????????cookie??????
????getPath??????????cookie?????·??
????getSecure????????????????????Э?鷢??Cookie??????true????????????????Э??????false?
????getValue??????????cookie???
????getVersion??????????cookie??????Э??汾setComment(String purpose????????cookie?????
????setPath(String url????????Cookie??????·??
????setSecure(Boolean flag?????????????????????e??Э????????cookie?????????Https??ssl
????setValue(String newvalue);cookie??????????????μ??
????setVersion(int v????????cookie??????Э??汾
????selenium WebDriver ???driver.manage().getCookies() ??driver.manage().addCookie(ck); ???cookie ????cookie
????????????cookie ?????browser.data??
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.Cookie;
public class Cookies {
public static void main(String[] args) {
WebDriver driver=DriverFactory.create();
driver.get("http://selenium.jd-app.com/wp-login.php");
driver.manage().timeouts().implicitlyWait(10?? TimeUnit.SECONDS);
WebElement user = driver.findElement(By.xpath("//*[@id='user_login']"));
user.clear();
user.sendKeys("username");
WebElement password = driver.findElement(By
.xpath("//*[@id='user_pass']"));
password.clear();
password.sendKeys("password");
WebElement submit=driver.findElement(By.xpath("//*[@id='wp-submit']"));
submit.submit();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File file=new File("broswer.data");
try
{
//delete file if exists
file.delete();
file.createNewFile();
FileWriter fw=new FileWriter(file);
BufferedWriter bw=new BufferedWriter(fw);
for(Cookie ck:driver.manage().getCookies())
{
bw.write(ck.getName()+";"+ck.getValue()+";"+ck.getDomain()+";"+ck.getPath()+";"+ck.getExpiry()+";"+ck.isSecure());
bw.newLine();
}
bw.flush();
bw.close();
fw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("cookie write to file");
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11