#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. 关于window.event.returnValue=false的用处

    window.event.returnValue=false放在提交表单中的onclick事件中则不会提交表单,如果放到超链接中则不执行超链接,也就是它禁止了或取消了请求,没有任何效果. 比如: if ...

  2. It is not the destination so much as the journey, they say.

    It is not the destination so much as the journey, they say. 人家说目的地不重要,重要的是旅行的过程.<加勒比海盗>

  3. jquery解析xml,获取xml标签名

    先给一个简单的XML,结构如下 <?xml version="1.0" encoding="uft-8" ?> <msg> <ro ...

  4. PHP的加解密:如何安装ioncube扩展?

    一.下载loader-wizard.php(支持php5.3.php5.4.php5.5.php5.6版本) ioncube提供了一个安装的向导程序,可以非常方便的帮助检测php的运行环境,自动给出提 ...

  5. GoAccess安装和使用介绍

    使用文档参考地址:https://my.oschina.net/mrco/blog/181737https://www.fanhaobai.com/2017/06/go-access.html goa ...

  6. jsp另外五大内置对象之response-设置头信息

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  7. 11.使用while和for循环分别打印字符串s=’asdfer’中每个元素

    1).for循环 s = 'asdfer' for i in s: print(i) 2).while循环 s = 'asdfer' while 1: print(s[index]) index += ...

  8. C Library - <limits.h>

    Introduction The limits.h header determines various properties of the various variable types. The ma ...

  9. Java多线程 编写三各类Ticket、SaleWindow、TicketSaleCenter分别代表票信息、售票窗口、售票中心。 售票中心分配一定数量的票,由若干个售票窗口进行出售,利用你所学的线程知识来模拟此售票过程。

    package com.swift; import java.util.ArrayList; import java.util.HashMap; import java.util.List; impo ...

  10. ssh整合思想初步 structs2 Spring Hibernate三大框架各自要点

    Web层用Structs2的action Service层用Spring的IoC和aop以及JdbcTemplate或者Transaction事务(创建对象及维护对象间的关系) Dao层用Hibern ...