繁体   English   中英

如何从坐标获取文本属性?

[英]How to get text attribute from coordinates?

我正在尝试使文本形成一个特定的元素。 该页面有许多TextViews。 所有文本元素都具有相同的resource-id和classname。 因此, driver.findElement()和所有driver.findElement()搜索的方法在这里都不起作用。

从该项目复制文本属性的唯一方法是使用X,Y坐标。

有什么方法可以获取文本形式的特定坐标?

您可以执行此操作,仍然需要xpath driver.findElement.. ,请尝试:

driver.findElementByXPath("//*[@x='249' and @y='458']").getText();

要么

driver.findElementByXPath("//*[@x='249' and @y='458']").getAttribute("attributeName");

确保您的元素具有属性xy ,如下所示:

属性

但是有时xy find元素并不能提供唯一性,而且如果应用程序发生了更改,这也很容易更改。

我找到了解决方法。 我们可以使用元素的完整层次结构。 在父母和孩子之间轻松使用/

像这样:

driver.findElement(By.xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.i[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.support.v4.view.ViewPager[1]/android.view.ViewGroup[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[2]/android.widget.TextView[2]")).getText();

UiAutomator2不显示此XPATH属性。 我使用Katalon studio-Mobile Spy查找了完整的Xpath层次结构

暂无
暂无

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

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