python+selenium+unittest实现自动登录

from selenium import webdriver
import unittest
import time

class HomePageLogin(unittest.TestCase):
def setUp(self):
print(‘开始执行测试用例:’)
url = ‘填入登录页面的链接’
self.driver = webdriver.Chrome()
self.driver.get(url)

def test_bubutton(self):
   self.driver.find_element_by_xpath('用xpath定位账号输入框').clear()
   self.driver.find_element_by_xpath('用xpath定位到的账号输入框').send_keys('输入账号')
   self.driver.find_element_by_xpath('账号输入框').clear()
   self.driver.find_element_by_xpath('密码输入框').send_keys('输入密码')
   self.driver.find_element_by_xpath('密码输入框').click()
   time.sleep(3)
 
     def tearDown(self):
    print('一条用例执行完成')
    self.driver.quit()

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

你可能感兴趣的:(selenium,xpath,unittest)