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

  • 相关阅读:
    解决“此计算机上已安装了试用版。必须先卸载以前安装的试用版后才能安装另一个试用版。”
    Windows 7 快捷键
    【译】部署Asp.Net MVC 网站到Winodws Azure
    jqGrid专题:搜索
    jqGrid专题:格式化数据
    jqGrid专题:事件文档
    jqGrid专题:方法文档
    jqGrid专题:数据加载
    jqGrid专题:参数文档
    jqGrid专题:jqGrid原理
  • 原文地址:https://www.cnblogs.com/SusanXX/p/8193857.html
Copyright © 2011-2022 走看看