• #1 楼 @lihuazhang 好的,主要我也搜索了,想看看有没有更好的解决办法,下次注意

  • @ding7473417 @chenhengjie123 @wang04170 在对混合型 APP 进行测试的时候,嵌入到 App 中的第三方 WebView,在查上下文信息的时候,找不到对应的 WebView。用 get_contexts 获取所有 context,也只获取到了 NATIVE_APP。没办法切换到 webview,我要获取里面的元素,该怎么办呢?

  • @ding7473417 @wang04170 @chenhengjie123 谢谢,问题顺利解决,好开心,谢谢谢谢

  • #1 楼 @ding7473417 我查了一下,说是要用 4.4 的,我用模拟器,4.4.2 的也是报这个错

  • #1 楼 @ding7473417 为什么我一用这个 driver.context(“WEBVIEW”),就报错呢?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: 10.62 seconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
    System info: host: '123TY-20150623B', ip: '172.16.18.133', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_38-ea'
    Session ID: 1d9d6db2-062c-4cea-a309-e87df1551ce9
    Driver info: io.appium.java_client.AppiumDriver
    Capabilities [{platform=WINDOWS, app=D:\andriod\test\apps\智农通 V2.2.5.apk, javascriptEnabled=true, appActivity=com.dbn.OAConnect.UI.LauncherSwitchActivity, browserName=, networkConnectionEnabled=true, desired={platformVersion=4.3, platform=WINDOWS, app=D:\andriod\test\apps\智农通 V2.2.5.apk, platformName=Android, deviceName=test, browserName=, appActivity=com.dbn.OAConnect.UI.LauncherSwitchActivity, appPackage=com.dbn.OAConnect}, locationContextEnabled=false, appPackage=com.dbn.OAConnect, platformVersion=4.4.2, databaseEnabled=false, deviceName=emulator-5554, platformName=Android, webStorageEnabled=false, warnings={}, takesScreenshot=true}]
    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:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:76)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:389)
    at org.openqa.selenium.By$ById.findElement(By.java:214)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
    at com.Nxin.test.TestMall.test(TestMall.java:130)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

  • #20 楼 @vincent 哦哦,uiautomatorviewer 里没有显示 source-id,我获得的那个 id 是在代码里看到的

  • #14 楼 @vincent 你的意思是这样写吗?dr.findElement(By.id("com.chnMicro.MFExchange:id/tab_account")).click();
    这样写不行呢

  • #16 楼 @pianai 我之前也是用的 swipe 也是不行,但是不知道为什么,后来我这样写的,就可以了 JavascriptExecutor js = (JavascriptExecutor) dr;
    HashMap swipeObj = new HashMap();
    swipeObj.put("startX", 420.0);
    swipeObj.put("startY", 400.00);
    swipeObj.put("endX", 30.0);
    swipeObj.put("endY", 400.0);

    swipeObj.put("duration", 0.4);
    // 滑动
    for (int i = 0; i < 3; i++) {
    try {
    js.executeScript("mobile: swipe", swipeObj);
    } catch (WebDriverException ex) {
    ex.printStackTrace();
    }
    }

  • #10 楼 @xuxu 请问那我该怎么找呢?classname 相同的元素有太多个了,我怎么能知道我要找的是哪个呢?

  • #7 楼 @xuxu 我有源代码,然后通过源代码的 id 去找,为什么报错提示找不到呢?

    我是这样写的 driver.findElementById("tab_account");,对吗?

  • #7 楼 @xuxu 我试过这个方法,但是相同的 class name 元素有 43 个,我怎么知道我要找的那个的索引呢?

  • #2 楼 @xuxu
    请问我要找下面导航里的东西怎么找呢?比如我要点击个人中心,跳转至个人中心页面,我怎么找到个人中心这个控件呢?

  • #2 楼 @xuxu 解决了,非常感谢

  • #2 楼 @xuxu 非常感谢你的回答,我去试试