zoukankan      html  css  js  c++  java
  • 操作HTML5存储对象

    读取HTML5的localStorahe和sessionStorage的内容,并删除存储的内容。

    #!usr/bin/env python  
    #-*- coding:utf-8 -*-  
    #操作HTML5存储对象
    
    from selenium import webdriver
    import unittest,time
    
    class Html5Storage(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
    
        def test_Html5localStorage(self):
            localStorageUrl = 
                'http://www.w3school.com.cn/tiy/loadtext.asp?f=html5_webstorage_local'
            self.driver.get(localStorageUrl)
            time.sleep(2)
            #通过JavaScript语句,获取存储在localStorage中的lastname的值
            lastName = self.driver.execute_script('return localStorage.lastname')
            print('lastName:',lastName)
            self.assertEqual('Gates',lastName)
            #通过JavaScript语句'localStorage.clear();'清除所有存储在localStorage中的存储值
            self.driver.execute_script('localStorage.clear();')
            #清除存储在localStorage中的存储值后再次查看lastname的值
            last_Name = self.driver.execute_script('return localStorage.lastname')
            self.assertEqual(None,last_Name)
    
        def test_Html5SessionStorage(self):
            sessionStorageUrl = 
                "http://www.w3school.com.cn/tiy/loadtext.asp?f=html5_webstorage_session"
            self.driver.get(sessionStorageUrl)
            time.sleep(2)
            self.driver.find_element_by_tag_name('button').click()
            time.sleep(2)
            clickCpunt = self.driver.execute_script('return sessionStorage.clickcount')
            print('clickCpunt:',clickCpunt)
            self.assertEquals(1,int(clickCpunt))
            self.driver.execute_script('sessionStorage.clear();')
            click_count = self.driver.execute_script('return sessionStorage.clickcount')
            self.assertEqual(None,click_count)
    
        def tearDown(self):
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    Sun开发的JINI技术在网络中的应用
    让memcached和mysql更好的工作
    Nginx+Tomcat+memcached负载均衡实现session共享
    Nginx 简单的负载均衡配置示例
    数据库sharding(scale up to scale out)
    docker专题(2):docker常用管理命令(上)
    UMDF
    编程精粹:编写高质量的C语言代码———笔记一
    子矩阵中共享1的最长对角线
    Print the numbers between 30 to 3000.
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8278753.html
Copyright © 2011-2022 走看看