1 #Author:xiaoxiao2 3 fromSeleniumImportWebdriver4 ImportUnitTest5 6 classDownLoad (unittest. TestCase):7 #Initialization Work8 defsetUp (self):9 #Open BrowserTenSelf.driver =Webdriver. Firefox () OneSelf.driver.implicitly_wait (10) ASelf.driver.get ("http://photo.163.com") - defTestdownloaf (self): - #Find out more button and click theKnowbutton = Self.driver.find_element_by_link_text ("Learn More") - Knowbutton.click () - #Get Window Handle -Windowhanle =Self.driver.current_window_handle +Windowhanles =Self.driver.window_handles - forHandleinchWindowhanles: + ifHandle! =Windowhanle: A Self.driver.switch_to.window (handle) at #Assertion Validation -Self.assertequal (Self.driver.current_url,"http://photo.163.com/cloudphotos/","Click Error") - #Get the iphone button and click -Iphonebutton = self.driver.find_element_by_id ("J-iphone") - Iphonebutton.click () -con = self.driver.find_element_by_id ("J-xbox-title"). Text in #Assertion Validation -Self.assertequal (Con,"iphone version download","Verifying iphone version download error") to defTearDown (self): + #Exit Browser - self.driver.quit () the * if __name__=='__main__': $Unittest.main ()
A second Python automation exercise