1. 程式人生 > >web自動化10-selenium登錄案例

web自動化10-selenium登錄案例

.com def chrom text end webdriver rdf element user

#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
def login(user,pwd):
driver.get("http://123.56.133.167:8180/web/loginpage?redirectUrl=%2Fweb%2Fadmin%2Fdoctorpage")
driver.maximize_window()
time.sleep(2)
driver.find_element_by_id(‘textfield‘

).send_keys(user)
time.sleep(2)
driver.find_element_by_id(‘passwordfield‘).send_keys(pwd)
time.sleep(2)
driver.find_element_by_id(‘submitbutton‘).click()
time.sleep(2)
return driver
def logout():
driver.find_element_by_id(‘logout‘).click()
time.sleep(2)
driver.quit()

if
__name__ == "__main__":
driver = webdriver.Chrome()
driver = login(‘admin‘,‘abc123‘)
t = driver.find_element_by_id(‘logout‘).text
if t == u"登出":
print (登錄成功‘)
else:
print (登錄失敗‘)
logout()

web自動化10-selenium登錄案例