2017-03-22 16 views
0

我正在使用appium_lib gem來自動執行我的android測試。我有一個元素,它沒有textcontent-desc,resource-id來標識。我嘗試了好幾種方法已經確定它像在UIAutomator中點擊使用邊界的元素?

find_element(class: "android.widget.Imageview").click #But the problem is, an other element also has the same class" 

我使用XPath單擊此

find_element(xpath: "//android.widget.LinearLayout[@index='1']/android.widget.ImageView[@index='0']").click 

不過它不會點擊元素上嘗試。

,我在此元素的UI的Automator找到邊界時[43,676][265,972]

如何使用這些信息來點擊元素。

回答

0

界限不是一個好方法,因爲它的值會在不同的設備和不同的屏幕尺寸上發生變化。 Xpath選項將是正確的方法。

但是,如果您仍然想嘗試邊界,您可以編寫一個自定義函數,您可以使用element.getLocation()方法返回對象的左上角。然後您需要將此值與Bounds數據進行比較。

+0

謝謝!我仍然無法在界限上取得成功,但我很幸運能夠按照層次結構定位元素。 –