appium學習筆記過程中遇到的一些問題彙總

持續更新系列。。

剛開始學時,一個小小的問題都可能要耗費很多時間,甚至是導致從入門到放棄的直接原因hhhhh 。所以寫下此篇總結或許會幫到剛開始學習的你!~

1.運行adb device報錯,解決辦法

2.提示   * daemon not running. starting it now on port 5037 *,解決辦法

  • 先查找5037是否被佔用netstat -aon|findstr "5037"

          

  • 關閉QQ音樂後,端口被釋放

3.運行腳本時報錯

  • 下載了Android 6.0 sdk後解決該問題

4.使用Appium Inspector時一直無法啓動apphttps://www.cnblogs.com/yoyoketang/p/6128803.html

  • 點擊啓動按鈕-放大鏡按鈕後,需要點擊“refesh“後纔會啓動app

5.在腳本中增加swipe(800,800,400,800)後,執行腳本報錯:selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command.

  • 通過https://www.cnblogs.com/yoyoketang/p/7766878.html這個方法實現滑動後再執行腳本就沒有報錯了。。

  • def swipeUp(driver, t=500, n=1):
        '''向上滑動屏幕'''
        l = driver.get_window_size()
        x1 = l['width'] * 0.5     # x座標
        y1 = l['height'] * 0.75   # 起始y座標
        y2 = l['height'] * 0.20   # 終點y座標
        for i in range(n):
            driver.swipe(x1, y1, x1, y2, t)
    
    def swipeDown(driver, t=500, n=1):
        '''向下滑動屏幕'''
        l = driver.get_window_size()
        x1 = l['width'] * 0.5          # x座標
        y1 = l['height'] * 0.25        # 起始y座標
        y2 = l['height'] * 0.75         # 終點y座標
        for i in range(n):
            driver.swipe(x1, y1, x1, y2,t)
    
    def swipLeft(driver, t=500, n=1):
        '''向左滑動屏幕'''
        l = driver.get_window_size()
        x1 = l['width'] * 0.75
        y1 = l['height'] * 0.5
        x2 = l['width'] * 0.25
        for i in range(n):
            driver.swipe(x1, y1, x2, y1, t)
    
    def swipRight(driver, t=500, n=1):
        '''向右滑動屏幕'''
        l = driver.get_window_size()
        x1 = l['width'] * 0.25
        y1 = l['height'] * 0.5
        x2 = l['width'] * 0.75
        for i in range(n):
            driver.swipe(x1, y1, x2, y1, t)

     

6.如何獲取屏幕大小

  • 如下

  • # 獲取屏幕的size
    size = driver.get_window_size()
    print(size)
    # 屏幕寬度width
    print(size['width'])
    # 屏幕高度width
    print(size['height'])

     

7.執行登陸腳本後,app黑屏閃退

  • 使用調試版本的包即可正常登陸

  • ps.一個小小的引申:原則上應該要用debug的包,但native的操作,應該無所謂的,只有H5的才需要打開debug模式

8.打開本地文件os.system("F:\uploadFile.exe")報錯:OSError: [Errno 22] Invalid argument:..........

  • 轉義的問題,換成如下輸入方式解決問題

    os.system("F:\\uploadFile.exe")

     

9.書寫“from uiautomator import Device”出歎號提示

  • 執行“ pip install uiautomator”解決

10.腳本執行不報錯,但一直出警告信息“ResourceWarning: unclosed <socket.socket fd=144, family=AddressFamily.AF_INE”

  • 書寫以下代碼解決

  • warnings.simplefilter("ignore", ResourceWarning)

     

11.打印的日誌中文字符顯示亂碼

  • 將file_handler = logging.FileHandler(log_name)代碼改成如下解決

  • file_handler = logging.FileHandler(log_name,encoding='utf-8')

     

12.當elementid一樣,text不一樣時該怎麼定位

  • 用以下語句實現根據text來定位:find_element_by_android_uiautomator('new UiSelector().text(\"13795291583的空間\")')

  • https://www.cnblogs.com/forcepush/p/6721828.html

  • driver.find_element_by_android_uiautomator('new UiSelector().text("Custom View")').click() #text
    
    driver.find_element_by_android_uiautomator('new UiSelector().textContains("View")').click() #textContains
    
    driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("Custom")').click() #textStartsWith
    
    driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^Custom.*")').click() #textMatches

     

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章