如何点击 appium 中关注的元素.无法在 appium 中选择下拉列表的值 [英] How to tap on a element which is focused in appium. Unable to select value of a dropdown in appium

查看:59
本文介绍了如何点击 appium 中关注的元素.无法在 appium 中选择下拉列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了下拉值元素未显示在 uiautomatorviewer 中的问题.

I am facing an issue where the element of dropdown value is not showing in uiautomatorviewer.

虽然我通过屏幕的 getPageSource 检查了 XML DOM,但移动应用屏幕上显示的结果也没有暴露

While I have check the XML DOM by getPageSource of the screen and there also no value is been exposed of the results showing on mobile app screen

XML 片段如下:-

<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.demo.pass" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,145][540,196]" resource-id="com.demo.pass:id/frameSearchLocation" instance="6">
    <android.widget.EditText index="0" text="Bryson City" class="android.widget.EditText" package="com.demo.pass" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="true" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[30,145][510,196]" resource-id="com.demo.pass:id/autoCompleteSearchTextView" instance="0" />
    <android.widget.ImageView NAF="true" index="1" text="" class="android.widget.ImageView" package="com.demo.pass" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[457,148][502,193]" resource-id="com.demo.pass:id/imgCurrentLocation" instance="0" />
</android.widget.FrameLayout>

再三考虑,我尝试了键盘操作.我可以使用以下代码导航到该值

In a second thought, I tried keyboard operation. I am able to navigate to the value using below code

ad.pressKeyCode(20);

但我无法挖掘该值.我已经尝试了大部分的事情.喜欢:-

But I am not able to tap the value. I have tried most of the thing. Like:-

ad.pressKeyCode(66); // Press Enter 

TouchAction action = new TouchAction(ad);
action.perform();

由于 DOM 上没有用于下拉值的定位器,我无法在上面的代码中传递元素.

As there is no locator present on the DOM for dropdown values, I can't pass the element on above code.

由于名称为框架,我也尝试使用以下代码进行切换:-

As there is name as frame I also tried to switch using below code :-

ad.switchTo().frame(ad.findElement(By.xpath("com.demo.pass:id/frameSearchLocation")));

uiautomatorviewer 屏幕:-

uiautomatorviewer screen :-

请建议我在这种情况下应该怎么做.任何解决方案/建议将不胜感激.

Please suggest what I should do in that case. Any solution/suggestions will be appreciated.

推荐答案

下面的代码对我有用

        By filter =By.xpath("MYLOCATOR");
        System.out.println("About to click on result");
        Point point = ad.findElement(filter).getLocation();
        int elementCenterX = point.getX() + 80;
        int elementCenterY = point.getY() + 100;
        System.out.println("value of x = "+elementCenterX+"   value of y = "+elementCenterY);
        ad.tap(2, elementCenterX , elementCenterY , 0);

注意:- 您需要在上面的代码中根据您的要求调整 X 和 Y,并传递最近的定位器,如下拉菜单的文本框.

Note:- you need to adjust X and Y as per your requirement in above code and pass the nearest locator like text box of the dropdown.

这篇关于如何点击 appium 中关注的元素.无法在 appium 中选择下拉列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆