简体   繁体   English

Android Appium Python-element.get_attribute('text')不返回任何文本

[英]Android Appium Python - element.get_attribute('text') returns no text

I try to get the text attribute of an element in hybrid app. 我尝试获取混合应用程序中元素的text属性。

def test_example(driver):
   el = driver.find_element_by_id('com.access_company.twine.android.dmc:id/btnVideos')

   print el.get_attribute("text")

so there is a button with video icon and a text "Videos". 因此,有一个带有视频图标的按钮和一个文本“视频”。 Unfortunately the above code doesnt print anything. 不幸的是,上面的代码无法打印任何内容。 So i tried this: 所以我尝试了这个:

 print el.get_attribute("resourceId")

Surprisingly that works. 令人惊讶的是。 So what am I missing or doing wrong here? 那我在这里想念或做错了什么? Hope someone can help. 希望有人能帮忙。

UIAutomator UIAutomator

Regards 问候

For the text of the stated element try the following code : 对于指定元素的文本,请尝试以下代码:

el = driver.find_element_by_id('com.access_company.twine.android.dmc:id/btnVideos')
print el.text

Also el.get_attribute("resourceId") shall ideally return "btnVideos" 同样, el.get_attribute("resourceId")最好返回“ btnVideos”

Ok. 好。 After investigating more time I found the solution and i feel so dumb now. 经过研究更多的时间后,我找到了解决方案,我现在觉得很傻。 There was a button, but this is not clickable so the id i was taking was not actually the button with the text, but the parent which is a relative layout without text. 有一个按钮,但是这不是可单击的,因此我使用的ID实际上不是带有文本的按钮,而是父级,它是没有文本的相对布局。 duh.. By the way resourceId doesn't return only "btnVideos" but the full id instead. duh ..顺便说一句,resourceId不只返回“ btnVideos”,而是返回完整ID。 Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM