今天在学习使用 findElementByAndroidUIAutomator 定位元素的时候,遇到这样的一个问题,描述如下:
driver.findElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.LinearLayout\").childSelector(new UiSelecotr().className(\"android.widget.Button\").text(\"8\")").click();
我使用上面的代码定位如下图的元素:
定位过程中,出现报错,试了修正了几次,还是报错,报错如下:
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 43 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'WIN-AN7GGQLOUGK', ip: '192.168.61.2', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.android.calculator2, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=192.168.61.101:5555, platform=LINUX, appActivity=.Calculator, desired={appPackage=com.android.calculator2, appActivity=.Calculator, platformVersion=4.4, browserName=, unicodeKeyboard=true, platformName=Android, deviceName=S5, resetKeyboard=true}, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, unicodeKeyboard=true, platformName=Android, resetKeyboard=true}]
Session ID: a1f9e64b-97d4-4807-a1c9-ecc2e2c91a73
*** Element info: {Using=-android uiautomator, value=new UiSelector().className("android.widget.LinearLayout").childSelector(new UiSelecotr().className("android.widget.Button").text("8")}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
at io.appium.java_client.android.AndroidDriver.findElementByAndroidUIAutomator(AndroidDriver.java:394)
at com.app.cn.startapp.main(startapp.java:36)
有朋友说 appium 不支持 childSelector 和 fromParent 方法,是么?