用了 N 种方法都没有能够定位到。
先转到 webview 模式。

public void SwitchtoWebViewModel(AppiumDriver driver) throws Exception {
    try {
        Set<String> contextNames = driver.getContextHandles();
        for (String contextName : contextNames) {
            System.out.println(contextName);
            // 用于返回被测app是NATIVE_APP还是WEBVIEW,如果两者都有就是混合型App
            if (contextName.contains("WEBVIEW")) {
                driver.context(contextName);
                // appDriver.switchTo().window("WEBVIEW");
                break;
            }// end if
        }// end for

然后用 xpath,id,class 定位均告失败。

            SwitchtoWebViewModel(driver);
Sleeper.sleep();
driver.findElementByXPath("//div[@class='More']").click();

结果报错。

An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.25 seconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'wangjunbin', ip: '192.168.174.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 66c22069-a7f7-47ae-93b2-e72331108ba0
Driver info: boc.framework.appium.test.AppiumDriverTestCase$AppiumSwipeableWebDriver
Capabilities [{platform=LINUX, app=F:/Test/Eclipse/Android4EZDB/src/main/resources/Apps/EZDBpro.apk, appActivit  y=com.boc.directbank.activities.WelcomeActivity, javascriptEnabled=true, browserName=Android, networkConnectionEnabled=true, desired={platformVersion=4.2.1, app=F:/Test/Eclipse/Android4EZDB/src/main/resources/Apps/EZDBpro.apk, appActivit  y=com.boc.directbank.activities.WelcomeActivity, platformName=Android, deviceName=Android Emulator, device=Android, appPackage=com.ss.boc.direct.bank.activity}, locationContextEnabled=false, appPackage=com.ss.boc.direct.bank.activity, platformVersion=4.2.1, databaseEnabled=false, deviceName=Android Emulator, platformName=Android, webStorageEnabled=false, device=Android, warnings={}, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    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:599)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:449)
    at test.boc.smoke.finance.testFinance.toFinance(testFinance.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

大神们,有没有办法定位 HTML5 元素的!!


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