1.app 的安裝與卸載
driver.install_app(apk path):安裝app
driver.remove_app(app package name):卸載app
driver.is_app_installed(app package name):判斷app是否已安裝,已安裝返回true
2.關閉和啟動app
driver.close_app()
driver.launch_app()
3.將app放置后台n秒,n秒后,頁面自動回到前台
driver.background_app( n )
4.獲取當前頁面 和 啟動指定頁面
driver.current_activity()
driver.start_activity(包名,activity名)
可以使用在這樣的場景中,如果當前頁面是登錄頁就登錄,否則先打開登錄頁再登錄:
if driver.current_activity()==登錄頁面:
//...進行登錄操作
else:
driver.start_activity(包名,登錄頁面)
5.等待某個頁面出現
driver.wait_activity('.CustomLocaleActivity',3,1):等待3秒,每1秒檢查一次,頁面出現則返回true
6.獲取當前頁面的樹形結構源碼
driver.page_source
7.截圖 :driver.get_screenshot_as_file("我的.png")
8.獲取所有的contexts: driver.contexts
獲取當前頁面的context: driver.current_context
9.獲取當前屏幕的大小
width=self.driver.get_window_size()['width']
height=self.driver.get_window_size()['height']