zoukankan      html  css  js  c++  java
  • selenium 模块化实例

    一、函数的定义,并引用

    public_model.py

    #登陆
    def login(driver):
    driver.find_element_by_id("idInput").clear()
    driver.find_element_by_id("idInput").send_keys('username')
    driver.find_element_by_id("pwdInput").clear()
    driver.find_element_by_id("pwdInput").send_keys('password')
    driver.find_element_by_id("loginBtn").click()

    #退出
    def logout(driver):
    driver.find_element_by_link_text("退出").click()
    driver.quit()

    diaoyong_publicmodel.py  调用模块化的函数文件

    #coding=utf-8
    #调用public文件的登录与退出函数
    from selenium import webdriver
    from public_model  import login,logout

    driver = webdriver.Firefox()
    driver.implicitly_wait(10)
    driver.get("http://www.126.com")

    #登陆
    login(driver)

    #退出
    logout(driver)

    二、使用类进行模块化及引用

    public_class.py

    #encoding=utf-8
    class Login():
    def __init__(self):
    self.driver=driver
    def login(self):
    self.driver.find_element_by_id("idInput").clear()
    self.driver.find_element_by_id("idInput").send_keys('username')
    self.driver.find_element_by_id("pwdInput").clear()
    self.driver.find_element_by_id("pwdInput").send_keys('password')
    self.driver.find_element_by_id("loginBtn").click()

    #退出
    def logout(self):
    self.driver.find_element_by_link_text("退出").click()
    self.driver.quit()

    diaoyong_publicclass.py

    #coding=utf-8
    from selenium import webdriver
    #调用public文件的Login类里的函数
    from public_class import Login

    driver = webdriver.Firefox()
    driver.implicitly_wait(10)
    driver.get("http://www.126.com")

    #登陆
    Login(driver).login()

    #退出
    Login(driver).logout()

  • 相关阅读:
    优化MySchool数据库(存储过程)
    优化MySchool数据库(事务、视图、索引)
    优化MySchool数据库(四)
    优化MySchool数据库(三)
    SQLAchemy
    python操作mysql
    python队列
    零碎知识
    super深究
    Python操作RabbitMQ
  • 原文地址:https://www.cnblogs.com/bzdmz/p/10331909.html
Copyright © 2011-2022 走看看