zoukankan      html  css  js  c++  java
  • Base.py最基层的一些方法的封装--自己整理的一些小内容

    # -*- coding: utf-8 -*-

    '''
    Created on 2017年7月15日

    @author: Administrator
    '''
    from selenium import webdriver
    from selenium.common.exceptions import *


    class BasePage(object):
    '''
    所有页面对象(page object PO)类的父类,
    封装了页面的基本操作
    '''

    def __init__(self, driver):
      self._driver = driver


    def find_element(self, loc):
      "定位一个元素"
      return self._driver.find_element(*loc)

    def find_elements(self, loc):
      "定位一组元素"
      return self._driver.find_elements(*loc)

    def click_element(self, loc):
      "点击一个页面元素"
      ele = self.find_element(loc)
      ele.click()

    def click_link(self, loc):
      "点击一个页面链接"
      ele = self.find_element(loc)
      tagname = ele.tag_name
      if tagname != u"a":
        raise WebDriverException,"不是一个链接元素"
      ele.click()

    def input_text(self, loc, text):
      "向页面的文本框内输入text"
      ele = self.find_element(loc)
      ele.clear()
      ele.send_keys(text)
      return

    def select_radio(self, loc):
      "在页面点击选择单选按钮"
      ele = self.find_element(loc)
      ele.click()

    def select_checkbox(self, loc):
      "在页面点击选择筛选框"
      ele = self.find_element(loc)
      ele.click()

    #def deselect_checkbox(self, loc):
      #"取消选中的复选框"
      #pass

    def page_should_contain(self, text):
      xpath = "//*[contains(., '%s')]" %text
      #self._driver.implicitly_wait(3)
      try:
        self._driver.find_element_by_xpath(xpath)
      except:
        return False
      #finally:
      #self._driver.implicitly_wait(10)
      return True

    def get_alert_message(self):
      "获取alert窗口信息"
      msg = None
      try:
        alert = self._driver.switch_to_alert()
        msg = alert.text
        alert.accept()
      except:
        return None
      return msg

  • 相关阅读:
    doc文档生成带目录的pdf文件方法
    Android uses-permission 权限大全
    AndroidManifest.xml配置文件详解 (转)
    解决导入Android例子时“Unable to resolve target 'android-x' ”的错误
    Eclipse导入Android项目的方法(转)
    数据结构与算法问题 AVL二叉平衡树
    TinyXml 与 Rapidxml效率对照
    HDU 1176-免费馅饼(DP_逆推)
    【OpenCV新手教程之十四】OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑
    交换机基础
  • 原文地址:https://www.cnblogs.com/SusanXX/p/8193857.html
Copyright © 2011-2022 走看看