selenium-- highlighted elements are operating

Foreplay

When making web automation, we would like to know if the element is in operation, we can achieve by way of js

Real

from Selenium Import the webdriver
 Import the unittest, Time 


DEF highLightElement (Driver, Element):
     '' ' 
    encapsulated method of highlighting page elements 
    using JS code background color and border incoming page elements target 
   color respectively to green and red 
    '' ' 
    driver.execute_script ( " arguments [0] .setAttribute (' style ', arguments [. 1]); " , Element,
                           " background: Green; border: 2px red Solid; " ) 


class TestDemo (of unittest.TestCase) :
     DEF the setUp (Self): 
        self.driver = the webdriver.Chrome()

    def test_HighLightWebElement(self):
        URL= ' Http://www.sogou.com ' 
        self.driver.get (URL) 
        searchBox = self.driver.find_element_by_id ( ' Query ' )
         # call highlighted wrapper function elements, highlighting the search box 
        highLightElement (self .driver, searchBox) 
        the time.sleep ( . 3 ) 
        searchBox.send_keys ( ' test developers ' ) 
        sumitbutton = self.driver.find_element_by_id ( ' STB ' )
         # call highlighted wrapper function elements, the search button is highlighted 
        highLightElement ( self.driver, sumitbutton) 
        the time.sleep ( . 3 )
        sumitbutton.click()
        time.sleep(3)

    def tearDown(self):
        self.driver.quit()


if __name__ == '__main__':
    unittest.main()

 

Guess you like

Origin www.cnblogs.com/zouzou-busy/p/11285762.html