繁体   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