Webdriver Advanced Apps-Highlight the page elements you're working on

Source: Internet
Author: User
Tags border color

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.