簡體   English   中英

如何在Appium中使用UIAutomator查找元素

[英]How to find element using UIAutomator in appium

我正在使用appium測試android混合應用程序。 誰能告訴我如何使用UIAutomator查找元素,因為appium給出的xpath在我的情況下不起作用。

非常感謝!

我的應用程序已經在真實設備上經過測試(但也可以在模擬器上),並連接到我的桌面並運行它,打開一些屏幕/頁面。 比起我以管理員身份運行uiautomatorviewer.bat(奇怪,但是我必須以管理員身份運行)。 比起單擊UI Automator Viewer左上角的“設備屏幕截圖”圖標,我可以在右窗格中看到屏幕截圖和Android類。 我可以導航,單擊不同的元素並觀察其層次結構。

術語鏈接上方的View和ListView是否具有resource-id或text屬性?

我認為您可以嘗試以下操作:

xpath="(//android.widget.ListView[contains(@resource-id,'some_id')]//android.widget.View)[2]/android.widget.View"

嘗試找到該節點,然后創建該子節點的相對路徑。

// - means any after (any child)
/ - goes immediate after
[2] - the second item that corresponds the criteria

如果您知道text屬性的值,則可以使用類似以下內容的方法: [contains(@text, 'some part of text')]

嘗試這個:

driver.findElementsByXPath("//*[@class='android.view.View' and @index='0']");

按照這種方法,使用UIautomator從任何元素獲取attributec('contentDescription')-

self.driver.find_element_by_accessibility_id('SomeAccessibilityID').get_attribute('contentDescription')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM