簡體   English   中英

使用uiautomatorviewer,appium和python查找元素時出錯

[英]Error finding element using uiautomatorviewer, appium and python

UIAUTOMATORVIEWER的屏幕截圖

我正在嘗試編寫python代碼來驗證Dropbox中是否存在.mp3和相應的.json文件。

dropboxmp3txt = self.driver.find_element_by_xpath('//android.widget.ListView/android.view.View/android.widget.TextView[contains(@index, "1")]')
print dropboxmp3txt.text

這給了我輸出:

abc2016-05-05, 10.38.26.mp3完全可以!!!

我需要類似的xpath來查找.json文本。 在圖中, .mp3下方的一個。

我試着做:

dropboxmp3txt = self.driver.find_element_by_xpath('//android.widget.ListView/android.view.View[0]/android.widget.TextView[contains(@index, "1")]')
print dropboxmp3txt.text
dropboxjsontxt = self.driver.find_element_by_xpath('//android.widget.ListView/android.view.View[1]/android.widget.TextView[contains(@index, "1")]')
print dropboxjsontxt.text

但是,這給了我一個錯誤:

Traceback (most recent call last):
  File "dropboxshare.py", line 136, in test_1_view_checkbox
    dropboxtxt = self.driver.find_element_by_xpath('//android.widget.ListView/android.view.View[0]/android.widget.TextView[contains(@index, "1")]')
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 258, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/appium/webdriver/errorhandler.py", line 29, in check_response
    raise wde
NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

沒有為這兩個文本指定ID。.擴展名(.mp3和.json)唯一在這兩個文本中都是唯一的。

如何檢索這兩個文本?

文本abc2016-05-5,10.38.26.mp3abc2016-05-5,10.38.26.json我無法直接輸入。例如: xpath("//android.widget.ListView/android.view.View/android.widget.TextView[@index='1' and @text='abc2016-05-05, 10.38.26.mp3' ]") xpath("//android.widget.ListView/android.view.View/android.widget.TextView[@index='1' and @text='abc2016-05-05, 10.38.26.json' ]")

因為,其他一些.mp3.json可能會在下一次運行期間出現並占據那些位置。.在運行時會發生變化。.我需要首先知道該位置出現了什么文本。 我如何檢索它。任何想法???

您嘗試的xpath可能沖突。 嘗試//android.widget.ImageView/../android.widget.TextView[1]

它將返回兩個元素,因此請使用find_elements_by_xpath

暫無
暫無

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

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