標籤: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使用過程中踩坑