1、视频自动化,点击半窗,无法通过 id/video_title 获取播放视频名称,用 HierarchyViewer 可以识别出 ID 为 id/video_title

2、代码:

System.out.println(driver.findElementById("com.huawei.hwvplayer.youku:id/video_title").getText());

3、图片:

4、错误信息:

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 222 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.huawei.hwvplayer.youku, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=X2P5T14B17000047, platform=LINUX, appActivity=com.huawei.hwvplayer.framework.MainActivity, desired={appPackage=com.huawei.hwvplayer.youku, appActivity=com.huawei.hwvplayer.framework.MainActivity, newCommandTimeout=200, platformVersion=6.0, unicodeKeyboard=true, platformName=Android, deviceName=Android Test, resetKeyboard=true}, newCommandTimeout=200, platformVersion=6.0, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, unicodeKeyboard=true, platformName=Android, resetKeyboard=true}]
Session ID: 7311fbc5-60b3-468e-8cf5-3db606330bae
*** Element info: {Using=id, value=com.huawei.hwvplayer.youku:id/video_title}
    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:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:358)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:399)
    at com.test.HwVPlayer.HwVPlayerAutoTestCase_0012.HwVPlayerAutoTestCase_0012(HwVPlayerAutoTestCase_0012.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:822)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1130)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)


↙↙↙阅读原文可查看相关链接,并与作者交流