試了一下午,發(fā)現(xiàn)appium的swipe函數(shù)不能滑動,網(wǎng)上說已經(jīng)不支持這個(gè)函數(shù)。
看了大佬的博客發(fā)現(xiàn)其實(shí)支持的,只是需要傳入時(shí)間不能傳入數(shù)字
from appium import webdriver
from time import sleep
from appium.webdriver.common.touch_action import TouchAction
# from selenium import webdriver
from datetime import timedelta
chrome_options_h5={'androidProcess': 'com.tencent.mm:tools'}
desired_caps = {
'platformName': 'Android',
#本機(jī)
# 'deviceName': 'A02AECP8256TU',
# 'platformVersion': '7.0',
'deviceName': '12b8a7ca',
'platformVersion': '5.0.2',
# 'browserName':'Chrome',
'noReset':'true',
# 'appPackage': ' com.codemao.box',
# 'appActivity': 'com.codemao.box.module.welcome.FirstActivity',
'appPackage': ' com.tencent.mm',
'appActivity': '.ui.LauncherUI',
'unicodeKeyboard':'true',
'resetKeyboard':'true',
# 'chromedriverExecutable':"C:\Program Files\Python35\chromedriver.exe",
# 'automationName':'appium',
# 微信h5
'chromeOptions':chrome_options_h5
}
dr=webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
print('1')
sleep(5)
dr.find_element_by_xpath("http://*[@text='發(fā)現(xiàn)']").click()
print('2')
width=dr.get_window_size().get('width')
height=dr.get_window_size().get('height')
print(width)
print(height)
# 滑動功能
dr.swipe(int(width)/2,int(height)/2,int(width)/2,int(height)/4,duration=sleep(1))
sleep(2)
dr.find_element_by_xpath("http://*[@text='小程序']").click()
sleep(3)
dr.find_element_by_xpath("http://*[contains(@text, '美團(tuán)外賣')]").click()
sleep(6)
print(dr.contexts,'所有contexts')
print(dr.current_context,'當(dāng)前的')
參考大佬文章:
http://blog.csdn.net/achang21/article/details/78167793