python+selenium+pytest自动化测试之下拉选择框处理

应用场景:新增或者查询时,遇到下拉选择框,进行处理,本博客主要用于根据状态查询数据,对列表中的数据进行断言分析。

1.BasePage封装select操作:

 def select_option(self,locator,value,type="index"):
        self.wait_utilVisible(locator)
        se=self.get_element(locator)
        logging.info("选择的type为{0}".format(type))
        if type=="index":
            Select(se).select_by_index(value)
            logging.info("选择的index是{0}".format(value))
        elif type=="value":
            Select(se).select_by_value(value)
            logging.info("选择的值是{0}".format(value))
        else:
            Select(se).select_by_visible_text(value)
            logging.info("根据文本内容传的值是{0}".format(value))

2.select下拉框元素定位

     # 查询输入框-在职状态
    isLeave=(By.XPATH,"//select[@ng-model='filterOptions.IsLeave']")

3.功能Page中调用

    # 查询正常状态的值
    def search_by_isLeave(self):
        self.select_option(self.isLeave,1,type="index")
        self.get_element(self.Button_Search).click()
     # 获取第7列的数据
    def userlist_data_isleave(self):
        text=self.get_table_list(self.list_7)
        logging.info("获取的列表信息是{0}".format(text))
        return text

4.TestCase中使用

  def test_search_by_isleave(self,login_User):
        UserlistPage(login_User[0]).search_by_isLeave()
        assert "离职" not in UserlistPage(login_User[0]).userlist_data_isleave()

 

你可能感兴趣的:(Selenium)