zoukankan      html  css  js  c++  java
  • python webdriver关键字框架

    关键字框架推荐使用eval,不使用exec

    eval()函数有返回值,exec()函数无返回值

    teststep.txt

    open||chrome
    visit||https://www.126.com
    click||switchAccountLogin
    sleep||3

    主程序脚本

    keyword.py

    #encoding=utf-8
    from selenium import webdriver
    import time

    with open("teststep.txt") as fp:
    teststeps = fp.readlines()

    driver = ""

    def open(browser_name):
    global driver
    if "ie" in browser_name:
    driver = webdriver.Ie(executable_path = "e:\IEDriverServer")
    elif "chrome" in browser_name:
    driver = webdriver.Chrome(executable_path = "e:\chromedriver")
    else:
    driver = webdriver.Firefox(executable_path = "e:\geckodriver")

    def visit(url):
    global driver
    driver.get(url)

    def click(id):
    try:
    driver.find_element_by_id(id).click()
    except:
    print("click fail!")
    raise

    def sleep(times):
    time.sleep(int(times))

    for teststep in teststeps:
    action = teststep.split("||")[0] #action = "open"
    value= teststep.split("||")[1].strip() #value= "chrome"
    try:
    command = "%s("%s")" %(action,value) # 拼接函数func(参数1,参数2)"open("chrome")"
    eval(command) #利用eval()执行函数 open("chrome")
    except:
    print("执行",command,"有异常")

    print ("DONE!")
  • 相关阅读:
    Balanced Number [ZOJ 3416]
    动态树
    Jason的特殊爱好 [FZU 2113]
    Raney引理
    Tri Tiling [POJ 2663]
    糖尿病的虾青素+胰岛素疗法 (转)
    JAVASCRIPT 开发工具:aptana ,WebStorm
    众志和达,英文SOUL 存储与数据安全提供商
    健身音乐及其它
    nodejs + CompoundJS 资源
  • 原文地址:https://www.cnblogs.com/ff-gaofeng/p/12670279.html
Copyright © 2011-2022 走看看