1.方法一,使用tap
tap有兩個參數,元素位置和點擊持續時間。
一般語法是這樣的tap((x1,y1),(x2,y2)],100), 我們通過手機百度中,利用tap方法來點擊攝像頭按鈕來舉例。
1.元素定位
記住上面的元素坐標,下面需要用到。
2.tap代碼實現
- import os
- import time
- from appium import webdriver
- desired_caps ={ 'platformName': 'Android',
- 'platformVersion': '6.0.1',
- 'deviceName': 'KIW-AL10',
- 'noReset': True,
- 'appPackage': 'com.baidu.searchbox',
- 'appActivity': 'com.baidu.searchbox.SplashActivity',
- 'unicodeKeyboard': True,
- 'resetKeyboard': True
- }
- driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)#啟動app
- time.sleep(3) #app啟動后等待3秒,方便元素加載完成
- #模擬手指點擊操作
- driver.tap([(918,413),(1026,521)], 100)
解釋:上面tap方法中位置的元素點坐標是通過ui automator viewer獲取,持續時間100是指100毫秒。
以上文章來源:
http://blog.csdn.net/u011541946/article/details/77986197