1 #-*- coding:utf-8 -*- 2 __author__ = "carry" 3 4 5 from selenium import webdriver 6 import time 7 import unittest 8 9 class Blog(unittest.TestCase): 10 def setUp(self): 11 self.driver=webdriver.Firefox() 12 url="http://www.cnblogs.com " 13 self.driver.get(url) 14 def login(self,username,pwd): 15 self.driver.find_element_by_link_text("登录").click() 16 time.sleep(2) 17 self.driver.find_element_by_xpath(".//*[@id='input1']").send_keys(username) 18 self.driver.find_element_by_xpath(".//*[@id='input2']").send_keys(pwd) 19 self.driver.find_element_by_id("signin").click() 20 self.driver.save_screenshot('xxx.jpg') 21 time.sleep(2) 22 print self.driver.title 23 def is_login_sucess(self): 24 try: 25 text=self.driver.find_element_by_id("user_nav_blog_link").text 26 print text 27 return True 28 except: 29 return False 30 def test_01(self): 31 self.login("xxxx","xxxx") 32 result=self.is_login_sucess() 33 self.assertTrue(result) 34 def tearDown(self): 35 self.driver.quit() 36 37 if __name__ == '__main__': 38 unittest.main()