• 定位元素的封装


    封装定位元素和login函数,在fengzhuang.py中

    #coding=utf-8
    import time
    from selenium import webdriver
    #第三版本:封装定位元素
    def findID(driver,ID):
    return driver.find_element_by_id(ID)
    def findLINK(driver,LINK):
    return driver.find_element_by_link_text(LINK)
    def findCss(driver,css):
    return driver.find_element_by_css_selector(css)
    def findXpath(driver,xpath):
    return driver.find_element_by_xpath(xpath)
    def findTagname(driver,tagname):
    return driver.find_element_by_tag_name(tagname)
    def login(driver,name,pw):
    findLINK(driver,
    u'登录').click()
    time.sleep(2)
    findID(driver,'TANGRAM__PSP_10__userName').send_keys(name)
    findID(driver, 'TANGRAM__PSP_10__password').send_keys(pw)
    findID(driver, 'TANGRAM__PSP_10__submit').click()
    time.sleep(2)
    dirError=findID(driver,'TANGRAM__PSP_10__error').text
    driver.close()
    assert u'请您输入'
    in dirError


    在baidu.py中调用login函数
    #coding=utf-8
    import time
    from selenium import webdriver
    from fengzhuang import login
    driver=webdriver.Firefox()
    driver.maximize_window()
    driver.implicitly_wait(30)
    driver.get('https://www.baidu.com/')
    login(driver,'panda','123456')
    time.sleep(3)
    driver.quit()
     
  • 相关阅读:
    webpack简介与使用
    webpack使用小记
    H5常用技巧
    mac 终端 常用命令
    vue.js学习资料
    git clean(转载)
    HTML5 移动端的上下左右滑动问题
    HTML5+CSS3 loading 效果收集--转载
    使用Chrome DevTools的Timeline分析页面性能
    phantomjs 是什么?----主要是mac下面
  • 原文地址:https://www.cnblogs.com/sunny0/p/7552295.html
Copyright © 2020-2023  润新知