一个简单自动登录

 
import time
from selenium import webdriver


class Login:
    def testLogin(username,password):
        login_url = "http://47.98.62.0:8092/#/login"
        driver = webdriver.Chrome(executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
        driver.maximize_window()
        time.sleep(1)
        driver.get(login_url)

        name=driver.find_element_by_id('username')
        name.clear()
        name.send_keys(username)
        time.sleep(1)

        passwd=driver.find_element_by_id('password')
        passwd.clear()
        passwd.send_keys(password)
        time.sleep(1)

        driver.find_element_by_xpath('/html/body/app-root/div/app-login/div/div/div/button').click()
        time.sleep(2)

        try:
            Index_text=driver.find_element_by_xpath('/html/body/app-root/div/app-layout/div/nz-layout/nz-layout/'
                                                    'nz-layout/div/div/default/div/div').text

            text_in='感谢使用CashLoan系统!'

            if(Index_text==text_in):
                print('登录成功')

        except Exception as info:
            print(info)


    if __name__ == '__main__':
        testLogin('admin',12345)

猜你喜欢

转载自www.cnblogs.com/huhaitao/p/11990455.html