from appium import webdriver import time desired_caps = {} desired_caps['platformName'] = 'Android' #手机系统 desired_caps['platformVersion'] = '5.1.1' #手机系统版本 desired_caps['deviceName'] = 'eef8e4e6' #cmd----> adb devices可查看到 desired_caps['appPackage'] = 'com.smartisanos.calculator' desired_caps['appActivity'] = '.Calculator' #cmd----> adb shell dumpsys activity activities:未找到该activity,按网上随意写后,竟然成功了,也是醉了…… driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) time.sleep(5) driver.find_element_by_id("com.smartisanos.calculator:id/digit1").click() driver.find_element_by_id("com.smartisanos.calculator:id/add").click() driver.find_element_by_id("com.smartisanos.calculator:id/digit5").click() driver.find_element_by_id("com.smartisanos.calculator:id/equal").click() driver.quit()
'''test001 手机:网易邮箱登录''' #coding=utf-8 from appium import webdriver import time from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC desired_caps ={ 'platformName':'Android', 'deviceName':'eef8e4e6', #cmd----> adb devices可查看到 'platformVersion':'5.1.1', #'app': 'C:\Users\tians\workspace\AlbumTest\app\Album_netease.apk', 如APP已在手机上安装,不需此命令,如需要从本机安装至手机,这此命令 'appPackage': 'com.netease.cloudalbum',#定位元素时查看 'appActivity': '.Activity.AppEncryptActivity',# cmd----> adb shell dumpsys activity activities----> 查看realActivity后面的名字 'unicodeKeyboard': True, #解决字符输人错误问题 'resetKeyboard': True #运行完成后充值软键盘状态 } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) time.sleep(5) #网易云相册:登录和验证 user = WebDriverWait(driver,5).until(EC.presence_of_element_located((By.ID,"com.netease.cloudalbum:id/UserName"))) user.send_keys("tianshixiao8@126.com") #driver.find_element_by_id("com.netease.cloudalbum:id/UserName").send_keys("8@126.com") driver.find_element_by_id("com.netease.cloudalbum:id/PassWord").click() driver.find_element_by_id("com.netease.cloudalbum:id/PassWord").send_keys("0128") #driver.hide_keyboard() driver.find_element_by_id('com.netease.cloudalbum:id/login').click() xc = WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,"android.widget.TextView"))) if xc.text == "本地相册": print("登录成功") else: print("登录失败") #进去左侧菜单 driver.find_elements_by_class_name("android.widget.ImageView")[0].click() #进入本地相册 driver.find_element_by_id("com.netease.cloudalbum:id/g_slidemenu_local_txt").click() driver.find_elements_by_xpath("//android.widget.GridView/android.widget.RelativeLayout")[0].click() #driver.find_element_by_name("Camera").click() driver.find_elements_by_xpath("//android.widget.GridView/android.widget.RelativeLayout")[0].click() driver.back() driver.back() #进入云相册 driver.find_elements_by_class_name("android.widget.ImageView")[0].click() driver.find_element_by_id("com.netease.cloudalbum:id/g_slidemenu_cloud_txt").click() yxc = WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,"android.widget.TextView"))) if yxc.text == "我的云相册": print("跳转云相册:成功") else: print("跳转云相册:失败") driver.find_elements_by_xpath("//android.widget.GridView/android.widget.RelativeLayout")[0].click() time.sleep(3) driver.find_elements_by_xpath("//android.widget.GridView/android.widget.RelativeLayout")[0].click() WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.ID,"com.netease.cloudalbum:id/photo_save_btn"))).click() driver.back() driver.back() driver.find_elements_by_class_name("android.widget.ImageView")[0].click() driver.find_element_by_id("com.netease.cloudalbum:id/g_slidemenu_set_txt").click() driver.find_element_by_name("注 销").click() driver.find_element_by_id("android:id/button1").click() WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.NAME,"登录"))) driver.quit()