zoukankan      html  css  js  c++  java
  • Python3 Selenium自动化web测试 ==> 第十一节 WebDriver高级应用 -- 显示等待 + 二次封装

    学习目的:


     

    掌握显示等待

    掌握二次封装

    正式步骤:


     

    step1:显示等待的代码示例

    # -*-  coding:utf-8 -*-
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    import time
    import os
    
    dr = webdriver.Chrome()
    url = 'http://renren.com/'
    dr.get(url)
    # dr 表示打卡浏览器
    # 30 表示超时总时长 30s
    # 1 表示循环查询时间,默认时间间隔0.5s
    # lambda x : x.find_element_by_xpath('//*[@id="email"]') 默认的官方格式,照旧
    x = WebDriverWait(dr,30,1).until(lambda x : x.find_element_by_xpath('//*[@id="email"]'))
    y = WebDriverWait(dr,30,1).until(lambda x : x.find_element_by_xpath('//*[@id="password"]'))
    z = WebDriverWait(dr,30,1).until(lambda x : x.find_element_by_xpath('//*[@id="login"]'))
    x.send_keys('308@qq.com')
    y.send_keys('*******')
    z.click()

    step2: 二次封装

    # -*-  coding:utf-8 -*-
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    import time
    import os
    
    class xianshidengdai():
    
        def __init__(self,driver):
            self.driver = driver
            self.timeout = 30
            self.t = 0.5
    
        def findelement(self,locator):
            element = WebDriverWait(self.driver,self.timeout,self.t).until(lambda x : x.find_element(*locator))
            return element
    
    if __name__ == "__main__":
        driver = webdriver.Chrome()
        driver.get('http://renren.com')
        test = xianshidengdai(driver)
        loc1 = (By.XPATH ,'//*[@id="email"]')
        test.findelement(loc1).send_keys('***')
        driver.close()
  • 相关阅读:
    java实验报告三
    学术论文撰写准备事项整理
    mac终端下运行shell脚本
    关于1*1卷积核的理解
    车牌识别项目的准备思路
    快捷键备忘
    跑caffe过程中的备忘
    caffe中全卷积层和全连接层训练参数如何确定
    从零开始足球战术分析
    卷积与反卷积以及步长stride
  • 原文地址:https://www.cnblogs.com/wuzhiming/p/11324878.html
Copyright © 2011-2022 走看看