#Encoding=utf-8ImportUnitTest fromSeleniumImportWebdriverImport Timedefhighlightelement (driver,element):#encapsulated method for highlighting page elements #use JavaScript code to set the background color and border color of the incoming page element object to #Green and RedDriver.execute_script ("arguments[0].setattribute (' style ', arguments[1]);", Element,"background:green; border:2px solid red;")classTestdemo (unittest. TestCase):defsetUp (self):#get the browser driver instanceSelf.driver = Webdriver. Ie (Executable_path ="E:\\iedriverserver") deftest_highlightwebelement (self): URL="http://sogou.com" #Visit Sogou homepageself.driver.get (URL) searchbox= self.driver.find_element_by_id ("Query") #Call the package function of the highlighted element to highlight the search input boxhighlightelement (Self.driver, SearchBox)#wait 3 seconds to see the highlight effectTime.sleep (3) Searchbox.send_keys (U"the road to glory automated testing") Submitbutton= self.driver.find_element_by_id ("STB") #Call the package function of the highlighted element to highlight the search buttonhighlightelement (Self.driver, Submitbutton) time.sleep (3) Submitbutton.click () Time.sleep (3) defTearDown (self):#Exit Browserself.driver.quit ()if __name__=='__main__': Unittest.main ()
Webdriver Advanced Apps-Highlight the page elements you're working on