Python+Selenium用例模块数据化之1:函数式编程和数据简单集中

以登录麦子学院为例

url = 'http://www.maiziedu.com/'
link_text = '登录'
account = '[email protected]'
pwd = 'abc123456'

def waituntil_load(driver,times,func):
    return WebDriverWait(driver,times).until(func)

def login_test():
    driver = webdriver.Chrome()
    driver.get(url)
    #driver.maximize_window()

    # driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[3]/div/div').click()  #关闭弹窗
    a = waituntil_load(driver,15,lambda driver:driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[3]/div/div'))
    a.click()

    driver.find_element_by_link_text(link_text).click() #点击登录
    time.sleep(2)

    input_zhanghao = driver.find_element_by_id('id_account_l')
    input_zhanghao.clear()
    input_zhanghao.send_keys(account)

    input_pwd = driver.find_element_by_id('id_password_l')
    input_pwd.clear()
    input_pwd.send_keys(pwd)

    driver.find_element_by_id('login_btn').click()

    time.sleep(10)


if __name__ == '__main__':
    login_test()

猜你喜欢

转载自blog.csdn.net/zupzng/article/details/80630485