from appium import webdriver import time desired_caps = { ‘platformName‘: ‘Android‘, ‘deviceName‘:‘8DF6R17503000072‘, ‘platformVersion‘: ‘8.0.0‘, "unicodeKeyboard":"true", "resetKeyboard":"true", ‘appPackage‘: ‘com.baidu.searchbox‘, ‘appActivity‘: ‘com.baidu.searchbox.MainActivity‘, } driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps) time.sleep(5) driver.get("https://m.baidu.com"); time.sleep(5) print(driver.current_package) print(‘-------------------------‘) print(driver.current_activity) print(‘-------------------------‘) print(driver.capabilities) print(‘-------------------------‘) driver.get("https://i.ifeng.com/"); time.sleep(5); driver.quit()
执行结果:
C:\Python38\pythonw.exe C:/Users/del/PycharmProjects/untitled1/cs/aaa.py
com.baidu.searchbox
-------------------------
.MainActivity
-------------------------
{‘platform‘: ‘LINUX‘, ‘webStorageEnabled‘: False, ‘takesScreenshot‘: True, ‘javascriptEnabled‘: True, ‘databaseEnabled‘: False, ‘networkConnectionEnabled‘: True, ‘locationContextEnabled‘: False, ‘warnings‘: {}, ‘desired‘: {‘platformName‘: ‘Android‘, ‘deviceName‘: ‘8DF6R17503000072‘, ‘platformVersion‘: ‘8.0.0‘, ‘unicodeKeyboard‘: True, ‘resetKeyboard‘: True, ‘appPackage‘: ‘com.baidu.searchbox‘, ‘appActivity‘: ‘com.baidu.searchbox.MainActivity‘}, ‘platformName‘: ‘Android‘, ‘deviceName‘: ‘8DF6R17503000072‘, ‘platformVersion‘: ‘8.0.0‘, ‘unicodeKeyboard‘: True, ‘resetKeyboard‘: True, ‘appPackage‘: ‘com.baidu.searchbox‘, ‘appActivity‘: ‘com.baidu.searchbox.MainActivity‘, ‘deviceUDID‘: ‘8DF6R17503000072‘, ‘deviceApiLevel‘: 26, ‘deviceScreenSize‘: ‘1440x2560‘, ‘deviceScreenDensity‘: 560, ‘deviceModel‘: ‘EDI-AL10‘, ‘deviceManufacturer‘: ‘HUAWEI‘, ‘pixelRatio‘: 3.5, ‘statBarHeight‘: 84, ‘viewportRect‘: {‘left‘: 0, ‘top‘: 84, ‘width‘: 1440, ‘height‘: 2344}}
-------------------------
Process finished with exit code 0