Javascript 无法获取屏幕中存在的对象的位置-Appium(Android)
我无法用Appium获取Android屏幕中元素的位置 我查看了关于上的getLocation()方法的文档,但没有获取元素位置的信息 我尝试使用整个对象:Javascript 无法获取屏幕中存在的对象的位置-Appium(Android),javascript,android,appium,webdriver-io,Javascript,Android,Appium,Webdriver Io,我无法用Appium获取Android屏幕中元素的位置 我查看了关于上的getLocation()方法的文档,但没有获取元素位置的信息 我尝试使用整个对象: console.log("Get location object: " + driver.getLocation('android=new UiSelector().resourceId("io.appium.android.apis:id/text"))')); 并具有特定值(X): 我期望从响应
console.log("Get location object: " + driver.getLocation('android=new UiSelector().resourceId("io.appium.android.apis:id/text"))'));
并具有特定值(X):
我期望从响应中得到X和Y值,但我在控制台中收到以下值:
获取位置对象:[object object]
获取位置参数“x”:未定义
我认为文件中有一个不正确的例子。它的工作原理应该是:
首先需要获取元素对象,然后使用其API获取位置
browser.getLocation()
用于获取GPS坐标我认为文档中的示例不正确。它的工作原理应该是:
首先需要获取元素对象,然后使用其API获取位置
browser.getLocation()
用于获取GPS坐标您可以尝试使用Appium Studio。因此,获取元素的位置非常简单
String locationX = client.elementGetProperty("NATIVE", "your-xpath-here", 0, "X");
String locationY = client.elementGetProperty("NATIVE", "your-xpath-here", 0, "Y");
这是为了分别得到X和Y坐标。有关详细说明,请参阅文档。您可以尝试使用Appium Studio。因此,获取元素的位置非常简单
String locationX = client.elementGetProperty("NATIVE", "your-xpath-here", 0, "X");
String locationY = client.elementGetProperty("NATIVE", "your-xpath-here", 0, "Y");
这是为了分别得到X和Y坐标。有关详细说明,您可以查看文档。我不能使用$selector,而是使用:const text=driver.getLocation('android=new-UiSelector().resourceId(“io.appium.android.api:id/text”);const location=text.getLocation();控制台日志(位置)
我在控制台[Object Object]上得到了这个结果,我编辑了代码以符合您的指示,但我仍然收到[Object Object],我对此进行了研究并实现了JSON.parse以尝试读取JSON对象(因为这是基于文档的预期结果:),但我收到了“SyntaxError:JSON中位置1处的意外标记o”错误消息。这是代码:const text=driver.$('android=new UiSelector().resourceId(“io.appium.android.api:id/text”))))const location=text.getLocation();console.log('location'+location);var obj=JSON.parse(location);console.log(obj)您可以这样尝试吗:const xLocation=text.getLocation('x');console.log(xLocation);//输出:150I不能使用$selector,而不是我使用的:const text=driver.getLocation('android=new-UiSelector().resourceId(“io.appium.android.api:id/text”);const location=text.getLocation();console.log(location)
我在控制台[Object Object]上得到了这个结果,我编辑了代码以符合您的指示,但我仍然收到[Object Object],我对此进行了研究并实现了JSON.parse以尝试读取JSON对象(因为这是基于文档的预期结果:),但我收到了“SyntaxError:JSON中的意外标记o位于位置1“错误消息。这是代码:const text=driver.$('android=new UiSelector().resourceId(“io.appium.android.api:id/text”))))const location=text.getLocation();console.log('location'+location');var obj=JSON.parse(location);console.log(obj)您可以这样尝试:const xLocation=text.getLocation('x');console.log(xLocation);//输出:150谢谢您的手术,但实际上我要在javascript上获取元素的位置,他们正在使用Java。谢谢您的手术,但实际上我要在javascript上获取元素的位置,他们正在使用Java。
String locationX = client.elementGetProperty("NATIVE", "your-xpath-here", 0, "X");
String locationY = client.elementGetProperty("NATIVE", "your-xpath-here", 0, "Y");