Appium :只有一个NATIVE_APP,跳转页面后提示:NoSuchElementException: Message: An element could not be locate..

异常:

NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

Appium :只有一个NATIVE_APP,跳转页面后提示:NoSuchElementException: Message: An element could not be locate.._第1张图片

这几天用appium写自动化,遇到一个问题,就是在A页面点击一个按钮进入B页面,B页面的元素怎么都获取不到。纠结了几天,在网上找了很多方法也没能解决,后来在官方文档看到:

The UiAutomator2 Driver for Android

Appium’s flagship support for automating Android apps is via the UiAutomator2 driver. (New to Appium? Read our introduction to Appium drivers). This driver leverages Google’s UiAutomator2 technology to facilitate automation on a device or emulator.

Development of the UiAutomator2 driver happens at the appium-uiautomator2-driver repo.

Older Android-based drivers include:
The UiAutomator Driver
The Selendroid Driver

Usage
The way to start a session using the UiAutomator2 driver is to include the automationName capability in your new session request, with the value UiAutomator2. Of course, you must also include appropriate platformName (=Android), platformVersion, deviceName, and app capabilities, at a minimum.

It is highly recommended to also set the appPackage and appActivity capabilities in order to let Appium know exactly which package and activity should be launched for your application. Otherwise, Appium will try to determine these automatically from your app manifest.

突然灵感一现,在启动app的参数配置中加上UiAutomator2 设置,是不是就可以了呢,结果加上后就真的好了,喜极而泣。方法如下:

                'platformName': 'Android',
                'platformVersion': platformVersion,
                'deviceName': deviceName,
                'automationName': 'uiautomator2',
                'newCommandTimeout': 240,
                "udid": XXXXX,
                "appActivity": appActivity,
                "appPackage": appPackage

希望对大家有帮助能解决你的问题。

你可能感兴趣的:(Appium)