import time from appium import webdriver from appium.webdriver.connectiontype import ConnectionType desired_caps = dict() desired_caps['deviceName'] = '192.168.234.104:5555' desired_caps['platformName'] = 'android' desired_caps['platformVersion'] = '5' desired_caps['appPackage'] = 'com.android.settings' # 设置的包名 desired_caps['appActivity'] = '.Settings' # 设置的界面名 desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_capabilities=desired_caps) # ------获取当前设备的分辨率---返回的是字典 # print(driver.get_window_size()) # print(driver.get_window_size()['width']) # ------截图---参数写文件路径 # driver.get_screenshot_as_file('screenshot.png') # driver.save_screenshot('123.png') # ------获取当前网络状态 print(driver.network_connection) # ------设置手机网络 # driver.set_network_connection(1) # # #不推荐---需写注释表明4为data_only # if driver.network_connection==4: # print(1) # else: # print(0) # # #推荐的 # if driver.network_connection==ConnectionType.AIRPLANE_MODE: # print(1) # else: # print(0) # ------发送键到设备 # driver.press_keycode(4) # time.sleep(2) # driver.press_keycode(25) # time.sleep(2) # driver.press_keycode(25) # time.sleep(2) # driver.press_keycode(24) # time.sleep(2) # driver.press_keycode(24) # ------打开通知栏 driver.open_notifications() time.sleep(3) # 关闭通知栏 driver.press_keycode(4) time.sleep(2) driver.quit()