Appium+python使用過程中踩坑

來源:互聯網
上載者:User

標籤:taskkill   stc   尋找   lte   ted   運行   error   定位元素   cond   

記錄Appium使用過程中的幾個問題:

1、重新運行時出現selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created. (Original error: Requested a new session but one was in progress)
原因是代碼中沒有殺死進程
查看appium進程:netstat -aon|findstr 4723
強制殺死進程:C:\PycharmProject\BuddyTest1>TASKKILL /F /PID 7756


2、定位元素時會出現異常,程式會報錯停止運行,有時想跳過異常執行下一步測試案例,需進行處理
NoSuchElementException異常:
1)定位錯誤
2)元素等待中
處理:
from selenium.common.exceptions import NoSuchElementException
try:

except:
列印
else:

例子:
#實名認證
def certificationBtn(self):
try:
self.by_text("實名認證")
except NoSuchElementException as msg:
print "尋找實名認證元素異常"%msg
else:
return self.by_text("實名認證")

3、報錯:URLError: <urlopen error [Errno 10061] >
原因:可能設定了代理
4、等待activity出現
原因:點擊跳轉時需等待某元素出現才可點擊,不然報錯,一般使用 time.sleep(seconds) ,但是等待的時間多久不確定。可使用等待activity函數。
使用:
# 等首頁面activity出現,30秒內

driver.wait_activity(".base.ui.MainActivity", 30)
5、出現IOError: [Errno 22] invalid mode (‘rb‘) or filename: ‘\xe2\x80\xaaD:\\ApiTestcase.xlsx‘報錯
方法:
方法1:路徑大寫D盤改成小寫 ,不成功
方法2:
編碼格式問題
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)

 

Appium+python使用過程中踩坑

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.