Appium-Python3--UI自动化-[-11-]-单选框定位选择

看图

 

 

 具体分析:

1.配偶,是,否分别为兄弟关系

2.所以可以通过配偶(大哥)定位二哥和弟弟

3.二哥为://android.view.View[@text='配偶']/following-sibling::android.view.View[1]/android.view.View/android.widget.RadioButton

   弟弟为://android.view.View[@text='配偶']/following-sibling::android.view.View[2]/android.view.View/android.widget.RadioButton

4.故我们可以将xpath中的定位分为两部分:

lend_request_loan_base_info_spouse_is_or_no_pre_xpath = //android.view.View[@text='配偶']/following-sibling::android.view.View[
lend_request_loan_base_info_is_spouse_is_or_no_last_xpath = ]/android.view.View/android.widget.RadioButton

5.中间的数字可以做参数化

6.通过用户输入是否知晓[‘0’,‘1’],0-知晓,1-不知晓

具体实现:

config.ini

lend_request_loan_base_info_spouse_is_or_no_pre_xpath = //android.view.View[@text='配偶']/following-sibling::android.view.View[
lend_request_loan_base_info_is_spouse_is_or_no_last_xpath = ]/android.view.View/android.widget.RadioButton

locator(读取config.ini)


LocatorSalesLendRequestLoanInfo
# 配偶是否知晓
    lend_request_loan_base_info_spouse_is_or_no_pre_xpath = myConfig.getAppElement("lend_request_loan_base_info_spouse_is_or_no_pre_xpath")
    lend_request_loan_base_info_is_or_no_last_xpath = myConfig.getAppElement("lend_request_loan_base_info_is_spouse_is_or_no_last_xpath")

page(通过locator定位实现具体操作)

    def lend_request_loan_base_info_other_is_or_know(self,l_spouse,l_relatives,l_colleagues,l_other_contacts):
        """
        联系人是否知晓
        :param l_spouse:
        :param l_relatives:
        :param l_colleagues:
        :param l_other_contacts:
        :return:
        """
        logger.info("配偶是否知晓...%s,直系亲属是否知晓...%s,同事是否知晓...%s,其他联系人是否知晓...%s" % (l_spouse,l_relatives,l_colleagues,l_other_contacts))
        print("配偶是否知晓...%s,直系亲属是否知晓...%s,同事是否知晓...%s,其他联系人是否知晓...%s" % (l_spouse,l_relatives,l_colleagues,l_other_contacts))

        is_or_know_xpath1 = LocatorSalesLendRequestLoanInfo.lend_request_loan_base_info_spouse_is_or_no_pre_xpath + str(int(l_spouse)+1) + LocatorSalesLendRequestLoanInfo.lend_request_loan_base_info_is_or_no_last_xpath
        print(is_or_know_xpath1)
        self.click_element("xpath",is_or_know_xpath1)
click_element
 def click_element(self,method,content):

        if method == "id":

            # 显示等待元素可点击
            WebDriverWait(self.driver, 10, 0.1).until(expected_conditions.element_to_be_clickable((method, content)))
            # 点击元素
            self.driver.find_element_by_id(content).click()
        elif method == "xpath":

            # 显示等待元素可点击
            WebDriverWait(self.driver, 10, 0.1).until(expected_conditions.element_to_be_clickable((method, content)))
            # 点击元素
            self.driver.find_element_by_xpath(content).click()

        elif method == "text":

            loc = ("xpath", "//*[@text='%s']" % content)

            e = WebDriverWait(self.driver, 10, 0.1).until(expected_conditions.presence_of_element_located(loc))
            e.click()

        elif method == "uiautomator":
            time.sleep(1)
            self.driver.find_element_by_android_uiautomator('new UiSelector().text(\"' + content + '\")').click()

成功!

 

 

posted @ 2020-09-01 16:21  旅行没有终点  阅读(595)  评论(0编辑  收藏  举报