1 #Author:xiaoxiao 2 3 from selenium import webdriver 4 import unittest 5 6 class DownLoad(unittest.TestCase): 7 #初始化工作 8 def setUp(self): 9 #打开浏览器 10 self.driver = webdriver.Firefox() 11 self.driver.implicitly_wait(10) 12 self.driver.get("http://photo.163.com") 13 def testDownLoaf(self): 14 #找到了解更多按钮并点击 15 knowbutton = self.driver.find_element_by_link_text("了解更多") 16 knowbutton.click() 17 #获取窗口句柄 18 windowhanle = self.driver.current_window_handle 19 windowhanles = self.driver.window_handles 20 for handle in windowhanles: 21 if handle != windowhanle: 22 self.driver.switch_to.window(handle) 23 #断言验证 24 self.assertEqual(self.driver.current_url,"http://photo.163.com/cloudphotos/","点击错误") 25 #获取iphone按钮并点击 26 iphonebutton = self.driver.find_element_by_id("J-iphone") 27 iphonebutton.click() 28 con = self.driver.find_element_by_id("J-xbox-title").text 29 #断言验证 30 self.assertEqual(con,"iPhone版下载","验证iphone版下载错误") 31 def tearDown(self): 32 #退出浏览器 33 self.driver.quit() 34 35 if __name__ == ‘__main__‘: 36 unittest.main()
时间: 2024-10-15 18:48:30