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()
  • 相关阅读:
    将execl转换成pdf文件
    exBSGS模板
    fhqtreap的学习笔记
    bzoj3196: Tyvj 1730 二逼平衡树
    bzoj2226[Spoj 5971] LCMSum
    bzoj2120: 数颜色
    bzoj3236: [Ahoi2013]作业
    bzoj3208: 花神的秒题计划Ⅰ
    bzoj4143: [AMPPZ2014]The Lawyer
    bzoj1968: [Ahoi2005]COMMON 约数研究
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8278573.html
Copyright © 2011-2022 走看看