使用Selenium操作Cookie
来源:互联网 发布:淘宝店铺如何激活手机 编辑:程序博客网 时间:2024/04/29 09:08
package com.gloryroad.Demo;
import java.util.Set;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class testHandleFrame {
String url="http://www.sogou.com";
public WebDriver driver;
@BeforeMethod
public void setUp(){
driver=new FirefoxDriver();
driver.get(url);
}
@AfterMethod
public void tearDown(){
driver.close();
}
@Test
public void testCookie(){
Set<Cookie> cookies=driver.manage().getCookies();
Cookie newCookie=new Cookie("cookieName","cookieValue");
System.out.println("Domain-->name-->value-->expiry-->path");
for (Cookie cookie : cookies) {
System.out.println(String.format("%s--%s--%s---%s--%s", cookie.getDomain(),
cookie.getExpiry(),cookie.getName(),
cookie.getPath(),cookie.getValue()));
}
//删除cookie,通过Cookie的name属性
driver.manage().deleteCookieNamed("CookieName");
//第二种全部删除
driver.manage().deleteAllCookies();
//通过Cookie对象
driver.manage().deleteCookie(newCookie);
}
}
import java.util.Set;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class testHandleFrame {
String url="http://www.sogou.com";
public WebDriver driver;
@BeforeMethod
public void setUp(){
driver=new FirefoxDriver();
driver.get(url);
}
@AfterMethod
public void tearDown(){
driver.close();
}
@Test
public void testCookie(){
Set<Cookie> cookies=driver.manage().getCookies();
Cookie newCookie=new Cookie("cookieName","cookieValue");
System.out.println("Domain-->name-->value-->expiry-->path");
for (Cookie cookie : cookies) {
System.out.println(String.format("%s--%s--%s---%s--%s", cookie.getDomain(),
cookie.getExpiry(),cookie.getName(),
cookie.getPath(),cookie.getValue()));
}
//删除cookie,通过Cookie的name属性
driver.manage().deleteCookieNamed("CookieName");
//第二种全部删除
driver.manage().deleteAllCookies();
//通过Cookie对象
driver.manage().deleteCookie(newCookie);
}
}
0 0
- 使用Selenium操作Cookie
- selenium 操作cookie
- Python Cookie操作实战---requests&selenium&urllib2
- selenium:4.selenium的操作cookie 以及调用jsd
- selenium cookie
- 使用InternetSetCookie操作cookie
- 使用JavaScript操作Cookie
- ubuntu使用selenium自动化操作
- selenium webdriver学习(九)------------如何操作cookie
- 使用selenium操作PhantomJS的常用操作
- 关于使用jquery.cookie.js 操作cookie
- 使用selenium自动登录淘宝并获取cookie
- Selenium自动化测试:如何使用cookie跳过验证码登录
- jquery操作Cookie插件使用
- 如何使用PHP操作cookie
- 使用js对cookie操作
- js操作cookie 使用详解
- 使用JQuery进行cookie操作
- Qt获取某文件夹下的文件数目
- JVM学习笔记(二)------Java代码编译和执行的整个过程
- simhash的python实现
- mysql实现字符串主键自增
- 树莓派3 B型今天推出 – 64位四核A53 1.2GHz的BCM2837
- 使用Selenium操作Cookie
- 如何在Loadrunner11中解决HTTP BASIC认证登录报401的问题
- 三个月内获得三年的工作经验
- 数据挖掘-目录-正则化方法
- MulticastSocket 使用
- Ubuntu16.04 PHP7 TO PHP5.6
- 关于PEAP认证的过程说明
- 淘宝开源缓存框架taobao-pamirs-proxycache源码剖析
- socket阻塞与非阻塞,同步与异步