appium+Python 启动app(三)登录

我们根据前面的知识点,用uiautomatorviewer工具来获取我们当前的元素

(注:uiautomatorviewer 是 android sdk 自带的)

知识点:appium的webdriver有11种元素定位方法

1、find_element_by_id()

2、find_element_by_name()

3、find_element_by_class_name()

4、find_element_by_tag_name()

5、find_element_by_link_text()

6、find_element_by_partial_link_text()

7、find_element_by_xpath()

8、find_element_by_css_selector()

9、find_element_by_accessibility_id()

10、find_element_by_android_uiautomator()

11、find_element_by_ios_uiautomation()

下面进行QQ的登录测试

#coding=utf-8
from appium import webdriver
import time
desired_caps ={
    'platformName': 'Android',
    'deviceName': '127.0.0.1:62001',
    'platformVersion': '4.4.2',
    'appPackage': 'com.tencent.mobileqq',
    'appActivity': 'com.tencent.mobileqq.activity.SplashActivity',
    'unicodeKeyboard': 'True',  # unicodeKeyboard是使用unicode编码方式发送字符串
    'resetKeyboard': 'True'  # resetKeyboard是将键盘隐藏起来
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(5)
driver.find_element_by_id("com.tencent.mobileqq:id/btn_login").click()
driver.find_elements_by_class_name("android.widget.EditText").send_keys(u"3060382351")
driver.find_element_by_id("com.tencent.mobileqq:id/password").send_keys(u"123456")
driver.find_element_by_id("com.tencent.mobileqq:id/login").click()
View Code
原文地址:https://www.cnblogs.com/cnblogsadmin/p/8392197.html