自动化测试登录

#coding=utf-8

from selenium import webdriver
#from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait

account='maizi_test@139.com'
pwd='abc******'
#等待条件满足或者超时后退出
def get_ele_times(driver,times,func):
return WebDriverWait(driver,times).until(func)

def login_test():
d=webdriver.Firefox()
d.get('http://www.maiziedu.com/')
get_ele_times(d,10,
lambda d: d.find_element_by_css_selector('a[class="a globalLoginBtn"]')).click()
d.find_element_by_xpath('//li/input[@id="id_account_l"]').send_keys(account)
d.find_element_by_id('id_password_l').send_keys(pwd)
d.find_element_by_id('login_btn').click()
try:
     #登录错误时提示信息打印
tex=d.find_element_by_id('login-form-tips').text
print tex
print 'error'
except:
print'right!!!'

d.quit()

login_test()
posted @ 2017-11-01 11:04  Qigege  阅读(289)  评论(0编辑  收藏  举报