四:Appium元素className定位方式

classname定位
classname定位是根据元素类型来进行定位,但是实际情况中很多元素的classname都是相同的,
如上例中登录页面中的用户名和密码都是clasName属性值都是:“android.widget.EditText” 因此只能定位第一个元素也就是用户名,而密码输入框就需要使用其他方式来定位,这样其实很鸡肋.一般情况下如果有id就不必使用classname定位。

by_classname.py

from find_element.capability import driver

driver.find_element_by_class_name('android.widget.EditText').send_keys('自学网2018')
driver.find_element_by_class_name('android.widget.EditText').send_keys('zxw2018')
driver.find_element_by_class_name('android.widget.Button').click()

 

原文地址:https://www.cnblogs.com/zhenyu1/p/11942784.html