作者yuuyoru (朝久)
看板Python
标题[问题] python + Appium问题
时间Tue Oct 29 13:47:22 2019
https://imgur.com/a/cELeNf3
想要点击APP工具列的按钮
但是按钮元素不是没有ID,就是ID重复 (ClassName也重覆)
Name在新版APPIUM已无法使用 (虽然很多也没text)
目前尝试了三个写法,但是都没法定位到元素
想请教各位大大,是哪里有问题
----------------------------------------------
1.Xpath 方式
driver.find_element_by_xpath('//android.widget.LinearLayout/android.support.v7.app.ActionBar.Tab[1]/android.widget.LinearLayout/android.widget.ImageView').click()
按照层级去写入元素,但是运行超过十分钟还定位不到元素,後来APPIUM server就断线
了
urllib3.exceptions.ProtocolError: ('Connection aborted.',
RemoteDisconnected('Remote end closed connection without response'))
2.text转成 Xpath 方式
driver.find_element_by_xpath("//*[@text='订单']").click()
想定位按钮下方的文字,但是跟上面一样,运行很久後就断线
3.uiautomator 方式
driver.find_element_by_android_uiautomator('new
UiSelector().className("\android.support.v7.app.ActionBar.Tab\").clickable(true)').click()
运行後出现错误讯息,An element could not be located on the page using the
given search parameters
看起来是在介面中找不到指定的元素
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.125.4.230 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1572328047.A.4F9.html
1F:推 s860134: 根据我的经验 android 定位多数情形不会超过 3 秒 10/31 20:16
2F:→ s860134: 你可能先厘清一下 是 find element 卡了还是 click 卡了 10/31 20:17
3F:→ s860134: 另外最好可以附上 appium 的log 会更好诊断 10/31 20:18