zoukankan      html  css  js  c++  java
  • appium,元素定位和元素操作,使用uiautomatorviewer

    ###

    定位说三种定位:id,class,xpath

    ###

    操作说3种,点击,输入,获取元素值,

    ###

    代码示例:

    from appium import webdriver
    import time
    import unittest
    
    
    class Test_Demo(unittest.TestCase):
    
        def setUp(self):
            desired_caps={}
            desired_caps['platformName']='Android'
            desired_caps['platformVersion']='6.0'
            desired_caps['deviceName']='emulator-5554'
            desired_caps['noReset']='true'  # 使用这个,就会记住上一次你的点击记录,
            desired_caps['appPackage']='com.tencent.news'
            desired_caps['appActivity']='com.tencent.news.activity.SplashActivity'
            desired_caps['dontStopAppOnReset']='true'
            self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    
            time.sleep(8)
    
        def tearDown(self):
            pass
            # driver.quit()  #退出app
    
        def test_search_demo(self):
            self.driver.find_element_by_id("com.tencent.news:id/home_channel_search_box").click()
            self.driver.find_element_by_class_name("android.widget.EditText").send_keys("股票期权")
            self.driver.find_element_by_xpath("//*[@resource-id='com.tencent.news:id/search_history_title']").click()
            self.driver.implicitly_wait(5)
            text_ele = self.driver.find_elements_by_id("com.tencent.news:id/title_text")
            for item in text_ele:
                print(item.text)
    
            # print("text", text_ele)
    
    if __name__ == '__main__':
        unittest.main()

    ###

    代码解释:

    注意1,desired_caps['noReset']='true'  # 使用这个,就会记住上一次你的点击记录,比如同意协议,不进行更新,这样的弹框选择

    注意2,desired_caps['dontStopAppOnReset']='true',加上这个,就不用每次都重新启动app了,这样会大大的提高调试代码的效率,很重要,

    注意3,self.driver.implicitly_wait(5),隐式等待,这个很重要,有很多时候你明明是定位对了,但是就是报错找不到元素,那就试试等待,一般会是这个问题,

    注意4,元素的定位,定位方法有很多,到时候你再学学,

    注意5,元素的操作,操作的方法有很多,到时候你再学学,

    ###

    ###

  • 相关阅读:
    python入门-函数(二)
    python入门-函数(一)
    python入门-WHILE循环
    python入门-用户输入
    python入门-字典
    Spring Security授权 AccessDecisionManager
    Java的性能优化
    datahub
    vbs mytest
    spring发布和接收定制的事件(spring事件传播)
  • 原文地址:https://www.cnblogs.com/andy0816/p/15125769.html
Copyright © 2011-2022 走看看