新手区 appium webdriver 定位出错

April · 2016年03月11日 · 最后由 songz 回复于 2016年03月11日 · 1643 次阅读
  1. 用 UIautomator 定位到这样的元素
  2. 采用 content-desc 定位报错 AttributeError: 'WebDriver' object has no attribute 'findElementByAccessibilityId'
  3. 贴上我的代码 ```python #-- coding: UTF-8 -- import os import time import unittest from appium import webdriver global driver

class LoginAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps={}
desired_caps['device'] = 'android'
desired_caps['platformName']='Android'
desired_caps['browserName']=''
desired_caps['platformVersion']='4.4.2'
desired_caps['deviceName']='MI NOTE LTE' # 这是测试机的型号
desired_caps['appPackage']='com.jinlufinancial.android.prometheus'
desired_caps['appActivity']='com.jinlufinancial.android.prometheus.StartMovieActivity'
self.driver=webdriver.Remote('http://localhost:4723/wd/hub,desired_caps')

def tearDown(self):
self.driver.quit()

def test_login(self):
time.sleep(10)
self.driver.findElementByAccessibilityId("百元玩电影 Link")

if name == 'main':
suite = unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)

共收到 8 条回复 时间 点赞
findElementByAccessibilityId()

这个是 Java 的 API,你应该用 python 的应该是

find_element_by_name

但是貌似 1.5 这个方法被去除了。

先试试看吧

—— 来自 TesterHome 官方 安卓客户端

#1 楼 @zsx10110 谢谢,用你说的那个方法可以实现。一直以为在 uiautomator 里面 text 就是元素的 name 属性,难道是 content-desc?

#3 楼 @mymgbaby 我记得 你看下源码就能够发现,使用 name 查找,他会先检查 text 如果 text 没内容就会找 content-desc,所以 name 是不太好的,最好用哪个我真忘了,你可以具体都尝试下。哈哈

#4 楼 @zsx10110 嗯嗯,非常感谢!!!

python 中是 find_element_by_accessibility_id

#6 楼 @finelucky 谢谢,我刚才用了你说的,是可以的。那请问像这样的元素要怎么定位呢

#7 楼 @mymgbaby xpath,去看下

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册