zoukankan      html  css  js  c++  java
  • 高亮显示正在操作的页面元素

    #!usr/bin/env python
    #-*- coding:utf-8 -*-  
    """ 
    @author:   sleeping_cat
    @Contact : zwy24zwy@163.com 
    """ 
    #高亮显示正在操作的页面元素
    
    import unittest
    from selenium import webdriver
    import time
    
    def highLightElement(driver,element):
        #封装好的高亮显示页面元素的方法
        #使用JavaScript代码将传入的页面元素对象的背景颜色和边框颜色分别设置为绿色和红色
        driver.execute_script("arguments[0].setAttribute('style',arguments[1]);",
                              element,'background:green;border:2px solid red;')
    
    class TestDemo(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
    
        def test_HighLightWebElement(self):
            url = 'http://sogou.com'
            self.driver.get(url)
            searchBox = self.driver.find_element_by_id('query')
            #调用高亮显示元素的封装函数,将搜索输入框进行高亮显示
            highLightElement(self.driver,searchBox)
            time.sleep(3)
            searchBox.send_keys('光荣之路自动化测试')
            submitButton = self.driver.find_element_by_id('stb')
            highLightElement(self.driver,submitButton)
            time.sleep(3)
            submitButton.click()
            time.sleep(3)
    
        def tearDown(self):
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    Chapter 4
    Chapter 3
    chapter 2
    Python编程指南 chapter 1
    BASE64 编码和解码
    生成 PDF 全攻略【2】在已有PDF上添加内容
    IDEA 和 Eclipse 使用对比
    web 前端常用组件【06】Upload 控件
    聊聊 Web 项目二维码生成的最佳姿势
    依附大系统 【数据实时获取】解决方案
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8278573.html
Copyright © 2011-2022 走看看