zoukankan      html  css  js  c++  java
  • selenium_学习笔记——二次封装常用的方法

    # coding = utf-8
    '''
    二次封装元素方法
    加入循环查找方法,提高查找元素的稳定性
    '''
    from selenium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    
    class Base():
        def __init__(self, driver):
            # self.driver = webdriver.Firefox()
            self.driver = driver

      # 查找元素的过程封装了循环查找 def find_element(self, locator): element = WebDriverWait(self.driver, 30).until(lambda x: x.find_element(*locator)) return element def send_keys(self, locator, text): self.find_element(locator).send_keys(text) def click(self, locator): self.find_element(locator).click() if __name__ == "__main__": driver = webdriver.Firefox() driver.get("https://www.baidu.com") mydriver = Base(driver) # 元组 # ID = "id"   # XPATH = "xpath"   # LINK_TEXT = "link text"   # PARTIAL_LINK_TEXT = "partial link text" # NAME = "name"   # TAG_NAME = "tag name"    # CLASS_NAME = "class name"   # CSS_SELECTOR = "css selector" inp_loc = ("id", "kw") # mydriver.find_element(inp_loc) mydriver.send_keys(inp_loc, "bai") but_loc = ("id", "su") mydriver.click(but_loc)

     优势:可以使代码更稳定、封装了循环查找的方法

  • 相关阅读:
    java 项目的CAS搭建
    OpenStack Grizzly版本(Ubuntu 12.04)配置
    存储介质管理
    软件包管理
    终端和键盘
    Shell环境(environment)和配置(configuration)
    Linux 基本命令入门
    iptables的原理及使用
    移动小球 (sicily 1934) (双向链表)
    1010 Tempter of the Bone (杭电) (图Graph)
  • 原文地址:https://www.cnblogs.com/xiaolangjianke/p/9039699.html
Copyright © 2011-2022 走看看