#!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()
转载于:https://www.cnblogs.com/sleeping-cat/p/8278573.html