zoukankan      html  css  js  c++  java
  • 模块七 高级定位技巧

    999

     https://www.w3school.com.cn/xpath/xpath_syntax.asp

     语法介绍:

    import pytest
    from appium import webdriver
    from time import sleep
    
    from appium.webdriver.common.touch_action import TouchAction
    
    
    class TestDw():
        def setup(self):
            desire_cap = {}
            desire_cap['platformName'] = 'android'
            desire_cap['devicesName'] = '127.0.0.1:7555'
            desire_cap['appPackage'] = 'com.xueqiu.android'
            desire_cap['appActivity'] = 'view.WelcomeActivityAlias'
            desire_cap['dontStopAppOnReset'] = 'true'
            desire_cap['unicodeKeyBoard'] = 'true'
            desire_cap['resetKeyBoard'] = 'true'
    
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desire_cap)
            self.driver.implicitly_wait(10)
    
        def teardown(self):
            self.driver.quit()
    
        def test_search(self):
            print("搜索用例")
            """
            1.打开雪球app
            2.点击搜索输入框
            3.想搜索输入框里面输入“阿里巴巴”
            4.在搜索输入框里面选择“阿里巴巴”,然后进行点击
            5.获取这只相关阿里巴巴的股价,并判断这只股价的价格>200元
            """
            self.driver.find_element_by_id("com.xueqiu.android:id/tv_search").click()
            e16 = self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("阿里巴巴")
            self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name' and @text='阿里巴巴']").click()
            cureent_price = float(self.driver.find_element_by_id("com.xueqiu.android:id/current_price").text)
            assert  cureent_price > 200
            sleep(3)
            self.driver.back()
    
        def test_attr(self):
            """
            1.打开雪球应用首页
            2.定位首页搜索框
            3.判断搜索框是否可用,变查看搜索框name属性值
            4.打印搜索框这个元素的左上角坐标和它的宽高
            5.向搜索框输入alibaba
            6.判断阿里巴巴是否可见
            7.如果可见,打印搜索成功点击,如果不可见,打印搜索失败
            """
            ele = self.driver.find_element_by_id("com.xueqiu.android:id/tv_search")
            #判断是否可用
            search_enabled = ele.is_enabled()
            #查看name属性值
            print(ele.text)
            #查看左上角坐标值
            print(ele.location)
            #查看宽高
            print(ele.size)
            if search_enabled == True:
                ele.click()
                self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("alibaba")
                ele_alibaba = self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name' and @text='阿里巴巴']")
                # ele_alibaba.is_displayed()
                #get_attribute可以获得元素的几乎所有属性
                ele_displayed = ele_alibaba.get_attribute("displayed")
                if ele_displayed == 'true':
                    print("搜索成功")
                else:
                    print("搜索失败")
    
        def test_touchaction(self):
            action = TouchAction(self.driver)
            action.press(x=731,y=2083).wait(200).move_to(x=731,y=484).release().perform()
    
        def test_get_current(self):
            self.driver.find_element_by_id("com.xueqiu.android:id/tv_search").click()
            e16 = self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("阿里巴巴")
            self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name' and @text='阿里巴巴']").click()
            current_price = float(self.driver.find_element_by_xpath("//*[@text='09988']/../../..//*[@resource-id='com.xueqiu.android:id/current_price']").text)
            print(f"价格{current_price}")
            assert  current_price >200
    
    if __name__ == '__main__':
        pytest.main()

     

  • 相关阅读:
    浏览器 cookie
    c# 委托
    并不对劲的loj3106:p5339:[TJOI2019]唱、跳、rap 和篮球
    并不对劲的loj3095:p5329:[SNOI2019]字符串
    并不对劲的CF1365D&E&F: Solve The Maximum Subsequence Again
    并不对劲的loj3123:p5404[CTS2019]重复
    并不对劲的loj3046:p5327:[ZJOI2019]语言
    并不对劲的loj3115:p5362:[SDOI2019]连续子序列
    并不对劲的loj3113:p5360:[SDOI2019]热闹的聚会与尴尬的聚会
    并不对劲的bzoj2521:p5039:[SHOI2010]最小生成树
  • 原文地址:https://www.cnblogs.com/hantongxue/p/14403323.html
Copyright © 2011-2022 走看看