from appium import webdriver
des={ "deviceName": "127.0.0.1:62001", # D:\Program Files\Android SDK\platform-tools>adb devices
"platformName": "Android",
"platformVersion": "5.1.1",
"unicodeKeyboard": True,
"resetKeyboard": True,
"noReset": True,
"appActivity": "com.tencent.mobileqq.activity.SplashActivity", #D:\Program Files\Android SDK\build-tools->cmd->aapt dump badging+包的路径
"appPackage": "com.tencent.mobileqq" #D:\Program Files\Android SDK\build-tools->cmd->aapt dump badging+包的路径
}
driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',des)
print('是否安装了某个包:',driver.is_app_installed("com.tencent.mobileqq"))
import time time.sleep(2) driver.close_app() time.sleep(2) print('打开初始化中的APP') driver.launch_app() print('删除qqAPP') driver.remove_app("com.tencent.mobileqq") time.sleep(2) print('是否安装了某个包:',driver.is_app_installed("com.tencent.mobileqq")) driver.install_app(r'C:\Users\刘淑贤\Desktop') #此处填写APP安装包路径 time.sleep(2) print('是否安装了某个包:',driver.is_app_installed("com.tencent.mobileqq")) print('当前窗口',driver.current_context) #如果明明知道打开的页面有webview,但获取窗口时没有获取到的话,找开发打开webview调试器 print('返回所有窗口',driver.contexts) text_url=driver.find_element_by_id('url') text_url.send_keys('http://ui.imdsx.cn/uitester') driver.press_keycode(66) #执行安卓按键。66是回车, time.sleep(2) driver.switch_to.context(driver.contexts[1]) ele=driver.find_element_by_css_selector('#i1').send_keys('1233444') #driver.swipe()############手机左滑右滑操作,五个参数开始的x, 开始的y, 结束的x, 结束的y,拖拽时间 x=1000 y=1200 # start_x=1000*0.5 # start_y=1200*0.8 # end_x=1000*0.5 # end_y=1200*0.8 window_size=driver.get_window_size() #获取当前窗口尺寸{width:720,height:1280} x=window_size["width"] y=window_size["height"] ele=driver.find_element_by_id('url') ele.send_keys('http://m.taobao.com/?sprefer=sypc00#index') time.sleep(3) driver.press_keycode(66) time.sleep(4)
def up(time,x,y): #封装上滑屏幕 tart_x = x * 0.5 start_y = y * 0.8 end_x = x * 0.5 end_y = y * 0.8 driver.swipe(tart_x,start_y,end_x,end_y,time) up(300,x,y)