在Appium中获取异常NoClassDefFoundError

时间:2016-11-09 19:48:38

标签: java android selenium appium noclassdeffounderror

单击元素时,在Appium中获取异常 java.lang.NoClassDefFoundError:org / openqa / selenium / HasTouchScreen 。我在我的代码中使用了三个定位器(text,id,partialLinkText),但每次都得到相同的异常。 PFB App DOM截图,代码,异常,jarfile版本

  1. 硒 - 机器人-driver.jar
  2. java-client-4.1.2(1).jar
  3. 硒 - 服务器 - 独立-3.0.1.jar
  4. 我正在尝试单击文本“登录或”,以便我可以自动登录模块。但我只是陷入了第一步:(

    enter image description here

    代码

    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.android.AndroidDriver;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;
    
    public class searsLogin {
        AndroidDriver driver;
      @BeforeTest
      public void setup() throws MalformedURLException {
          DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("deviceName", "ccdcb242");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "ANDROID");
            capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
            capabilities.setCapability("platformName", "Android");
              capabilities.setCapability("appPackage", "com.sears.android");
                capabilities.setCapability("appActivity", "com.android.sears.activity.MenuDrawerActivity");
                 driver = (AndroidDriver) new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
               driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
      }
        @Test
      void execution()
      {
            // driver.findElementByName("Sign in or").click();/// contains method
     // boolean res = driver.findElement(By.name("Sign in or")).isDisplayed();  
    //boolean res =  driver.findElement(By.xpath("//*[contains(text(),'Sign in or')]")).isDisplayed();
      driver.findElement(By.partialLinkText("Sign in or")).click(); 
         }
       @AfterTest
      public void end()
      {
          driver.quit();
      }  }
    

    异常消息

    java.lang.NoClassDefFoundError: org/openqa/selenium/HasTouchScreen
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
    

2 个答案:

答案 0 :(得分:0)

您正在使用WEB定位器进行移动设备。 此操作的正确XPath将遵循:

By.xpath("//*[@text='Sign in or']")

答案 1 :(得分:-1)

在Appium v​​1.5.3 - Android中,要点击定位器“名称”,请尝试使用:

driver.findElementByAndroidUIAutomator(“new UiSelector()。text(\”Locator name \“)”)。click();

对于提到的截图  :driver.findElementByAndroidUIAutomator(“new UiSelector()。text(\”登录或\“)”)。click();