web自動化10-selenium登錄案例
阿新 • • 發佈:2017-09-25
.com def chrom text end webdriver rdf element user ).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()
#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‘
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
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登錄案例