• 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

  • 相关阅读:
    2013工作回望
    在Skyline 控件上面显示Web信息窗体
    Extjs xtype 为lable 设置
    纪念第一篇博客
    前端技术学习经验分享(第二、三天---学习过程)
    前端技术学习经验分享(第一天---布置学习环境)
    JS开发HTML5游戏《悠悠考拉》(三)
    JS开发HTML5游戏《悠悠考拉》(二)
    JS开发HTML5游戏《悠悠考拉》(一)
    产品经理C端转B端,我后悔了
  • 原文地址:https://www.cnblogs.com/SusanXX/p/8193857.html
Copyright © 2020-2023  润新知