问题
I am facing an issue where the element of dropdown value is not showing in uiautomatorviewer.
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
The XML snippet is as below:-
<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
And
TouchAction action = new TouchAction(ad);
action.perform();
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 screen :-
Please suggest what I should do in that case. Any solution/suggestions will be appreciated.
回答1:
This is a known issue. I have been doing Android App testing automation from last 2 years. I have encountered the same issue many times. Unfortunately, uiAutomator does not detect these kind of elements so we can't perform any actions on such elements.
Appium internally sends command to uiAutomator and uiAutomatar performs the actions on the device. uiAutomator can perform actions if uiAutomator sees those elements.
So I suggest you to don't spend much time on using TouchAction/java script/ pagesource or xPath because I have already tried hose solutions but none of them worked.
However, You can click on the elements using co-ordinates if the element is present at the same location every time (Not suggested if the elements in the drop down keep changing).
回答2:
Below code work for me
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);
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.
来源:https://stackoverflow.com/questions/46036972/how-to-tap-on-a-element-which-is-focused-in-appium-unable-to-select-value-of-a