#encoding=utf-8
import unittest
import time
from selenium import webdriver
from selenium.webdriver import ActionChains class VisitSogouByIE(unittest.TestCase): def setUp(self):
#启动IE浏览器
#self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer") def test_Cookie(self):
url = "http://www.sogou.com"
# 访问sogou首页
self.driver.get(url)
# 得到当前页面下所有的Cookies,并输出它们所在域、name、value、有效期和路径
cookies = self.driver.get_cookies()
for cookie in cookies:
print "%s -> %s -> %s -> %s -> %s" \
% (cookie['domain'], cookie["name"], cookie["value"], \
cookie["expiry"], cookie["path"]) # 根据Cookie的name值获取该条Cookie信息,获取name值为'SUV'的Cookie信息
ck = self.driver.get_cookie("SUV")
print "%s -> %s -> %s -> %s -> %s" \
% (ck['domain'], ck["name"], ck["value"], \
ck["expiry"], ck["path"]) # 删除cookie有2种方法
# 第一种:通过Cookie的name属性,删除name值为“ABTEST”的Cookie信息
print self.driver.delete_cookie("ABTEST") # 第二种:一次性删除全部Cookie信息
self.driver.delete_all_cookies()
# 删除全部Cookie后,再次查看Cookies,确认是否已被全部删除
cookies = self.driver.get_cookies()
print cookies # 添加自定义Cookie信息
self.driver.add_cookie({"name": "gloryroadTrain", 'value': ''})
# 查看添加的Cookie信息
cookie = self.driver.get_cookie("gloryroadTrain")
print cookie def tearDown(self):
# 退出IE浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()

Selenium WebDriver- 操作浏览器的cookie的更多相关文章

  1. Python3+Selenium2完整的自动化测试实现之旅(四):Selenium-webdriver操作浏览器、Cookie、鼠标键盘、警示框、设置等待时间、多窗口切换

    本篇学习总结webdriver模块操作浏览器.Cookie.鼠标键盘.警示框.设置等待时间.多窗口切换等方法的使用 1    浏览器控制 Selenium-webdriverAPI提供了对页面元素定位 ...

  2. selenium WebDriver 对浏览器标签页的切换

    关于selenium WebDriver 对浏览器标签页的切换,现在的市面上最新的浏览器,当点击一个链接打开一个新的页面都是在浏览器中打开一个标签页,而selenium只能对窗口进行切换的方法,只能操 ...

  3. selenium webdriver处理浏览器Cookie

    有时候我们需要验证浏览器中是否存在某个cookie,因为基于真实的cookie 的测试是无法通过白盒和集成测试完成的.WebDriver 提供了操作Cookie 的相关方法可以读取.添加和删除cook ...

  4. selenium webdriver(1)---浏览器操作

    启动浏览器 如何启动浏览器已在上篇文章中说明,这里还是以chrome为例,firefox.IE启动方式相同. //启动浏览器 import org.openqa.selenium.WebDriver; ...

  5. selenium webdriver操作各浏览器

    描述 本文主要是针对Chrome 62 , firefox57 ,和IE11 三个版本的操作.相关的driver .可点击以下链接.所有的driver 建议放在浏览器的目录下,本文中所有的driver ...

  6. Selenium webdriver 操作chrome 浏览器

    Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...

  7. Selenium webdriver 操作IE浏览器

    V1.0版本:直接新建WebDriver使用 import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetE ...

  8. java selenium (十) 操作浏览器

    本篇文章介绍selenium 操作浏览器 阅读目录 浏览器最大化 前进,后退, 刷新 public static void testBrowser(WebDriver driver) throws E ...

  9. selenium,webdriver模仿浏览器访问百度 基础2

    学python理念  :  代码要多敲 一定要多敲 哪怕很基础  注释要清晰 由于基础1有一些注释写的很详细, 在这里有些注释没有写的很详细 可以配合基础1一起学习哦 from selenium im ...

  10. 使用python selenium webdriver模拟浏览器

    selenium是进行web自动化测试的一个工具,支持C,C++,Python,Java等语言,他能够实现模拟手工操作浏览器,进行自动化,通过webdriver驱动浏览器操作,我使用的是chrome浏 ...

随机推荐

  1. feign容断忽略某些异常

    @HystrixCommand(ignoreExceptions={ BusinessException.class, IllegalArgumentException.class, BadCrede ...

  2. The great pleasure in life is doing what people say you cannot do.

    The great pleasure in life is doing what people say you cannot do.  人生最大的快乐是做到别人认为你做不到的事情.

  3. HttpServeletRequest

    一.HttpServeletRequest 接口(javax.servlet.http) 定义:public interface HttpServletRequestextends ServletRe ...

  4. ptxas fatal : Unresolved extern function Error 255

    This question already has an answer here: External calls are not supported - CUDA 1 answer I am tryi ...

  5. freebsd问题

    http://community.spiceworks.com/topic/91708-server-freezes

  6. iOS优化

    load妙用 aop面向切面编程 NSNumber Or Int @()适配64位 经过漫长时间的学习 你终于掌握了iOS大法 你找到了份iOS开发的工作 信誓旦旦的要开始你的coding生涯 老板对 ...

  7. 深度探索C++对象模型——关于对象

    引言 以前读<C++ Primer>的时候一直有一种感觉:该书虽然是C++入门书籍,初学者读之却觉晦涩,越往后读越是如此.等到稍加理解后再读该书,顿感醍醐灌顶,茅塞顿开.究其原因,在于原作 ...

  8. Python+selenium之测试报告(3)

    较测试报告(2),该文章将测试报告和测试截图存放在随机变动的文件夹下面,去除了要存放在指定文件夹下面的限制. 注:遇到问题有: 1.创建由时间自动拼接的多级文件夹 2. import os impor ...

  9. 日常-acm-三位数反转

    输入一个三位数,分理出它的百位,十位和个位,反转后输出. 样例输入: 127 样例输出: 721 tips:注意最后一位为0的情况,如360,输出063 #include <iostream&g ...

  10. UVA1607 Gates 与非门电路 (二分)

    题意:给你一个按发生时间的序列,表示与非门电路的输入,一开始全部输入是x,现在要改成尽量少的x,实现相同的功能. 题解:电路功能只有4中0,1,x,非x.那么如果一开始x改变了,输出结果不变,那么说明 ...