• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

获取控件失败

代码如下:
package com.longze.testcase;import io.appium.java_client.android.AndroidDriver;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.junit.runner.RunWith;import org.junit.runners.JUnit4;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.DesiredCapabilities;import java.net.URL;import java.util.concurrent.TimeUnit;/** * Instrumented test, which will execute on an Android device. * * @see Testing documentation */@RunWith(JUnit4.class)public class setupTest {    public AndroidDriver driver;    @Test    public void loginTest() {                           }    @Before    public void setUp() throws Exception {        DesiredCapabilities capabilities = new DesiredCapabilities();        //设置模拟器设备名称,命令行命令:adb devices可以查看到        capabilities.setCapability("deviceName", "192.168.158.102:5555");        //设置平台版本号        capabilities.setCapability("platformVersion", "7.0");        //设置自动化引擎名        capabilities.setCapability("automationName","Appium");        //设置平台名称:Android或者IOS等        capabilities.setCapability("platformName", "Android");        //设置需要安装的应用名称,注意:必须是本地的绝对路径//        capabilities.setCapability("app","F:\\work\\LongChunag\\app\\build\\outputs\\apk\\debug\\app-debug.apk");        //设置应用所在的包名,和下面的启动页面可以用命令行命令:aapt dump badging XXX.apk可以查到.        capabilities.setCapability("appPackage", "com.android.calculator2");  //"com.longze.longchuang");        //设置该应用启动页面        capabilities.setCapability("appActivity", ".Calculator");        //设置等待设备就就绪的超时时间        capabilities.setCapability("deliveredTimeout",30);        //下面二个参数使Appium支持中文输入.        capabilities.setCapability("unicodeKeyboard",true);        capabilities.setCapability("resetKeyboard",true);        //设置Appium 服务器端侦听端口.并实例化一个Session.        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);        Thread.sleep(3000);        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);        driver.findElementById("com.android.calculator2:id/digit_9").click();         Thread.sleep(1000);        driver.findElementById("com.android.calculator2:id/digit_8").click();        //driver.findElementById()    }    @After    public void tearDown() throws Exception {        driver.quit();    }}错误日志如下:
org.openqa.selenium.InvalidSelectorException: Locator Strategy 'css selector' is not supported for this session
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
System info: host: 'USER-Q47EI64IRI', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_181'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: .Calculator, appPackage: com.android.calculator2, automationName: Appium, databaseEnabled: false, deliveredTimeout: 30, desired: {appActivity: .Calculator, appPackage: com.android.calculator2, automationName: Appium, deliveredTimeout: 30, deviceName: 192.168.158.102:5555, platformName: android, platformVersion: 7.0, resetKeyboard: true, unicodeKeyboard: true}, deviceManufacturer: Genymotion, deviceModel: Custom Phone - 7.0.0 - API ..., deviceName: 192.168.158.101:5555, deviceScreenSize: 768x1280, deviceUDID: 192.168.158.101:5555, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: LINUX, platformVersion: 7.0, resetKeyboard: true, takesScreenshot: true, unicodeKeyboard: true, warnings: {}, webStorageEnabled: false}
Session ID: fa00c49e-1b5e-4cfe-9908-6e19feebc4d3
*** Element info: {Using=id, value=com.android.calculator2:id/digit_9}

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    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:371)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:417)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:70)
    at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
    at com.longze.testcase.setupTest.setUp(setupTest.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!