线程“主”中的异常java.lang.ClassCastException:无法将java.util.HashMap强制转换为org.openqa.selenium.WebElement

时间:2018-10-04 07:24:31

标签: java selenium automation appium-android

我正在使用此代码并产生此错误

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class HandlingScrollVertical {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        // TODO Auto-generated method stub


        DesiredCapabilities dc= new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

        //dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");

        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");

        dc.setCapability(MobileCapabilityType.APP, "/home/connexis/appium/AppiumMobile/src/main/java/Apps/ApiDemos.apk");

        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver<WebElement> driver= new AndroidDriver<WebElement>(url,dc);

        driver.findElementsByAccessibilityId("Animation").get(1).click();     
        /*WebElement info=driver.findElementsById("android:id/text1").get(1);


        int x1=info.getLocation().getX();
        int y1=info.getLocation().getY();



        int x2=x1 /2;
        int y2=y1 /2;


        TouchAction a = new TouchAction((MobileDriver) driver);
        a.press(info).moveTo(x1,y1).perform().release();*/
        Thread.sleep(8000);
        driver.quit();
    }

}

娱乐变量集:

Selenium Server独立版2.53

    Java-Client 5.0.4
    Emulator

错误日志:

Exception in thread "main" java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:397)
    at io.appium.java_client.DefaultGenericMobileDriver.findElements(DefaultGenericMobileDriver.java:54)
    at io.appium.java_client.AppiumDriver.findElements(AppiumDriver.java:167)
    at io.appium.java_client.FindsByAccessibilityId.findElementsByAccessibilityId(FindsByAccessibilityId.java:38)
    at io.appium.java_client.AppiumDriver.findElementsByAccessibilityId(AppiumDriver.java:203)
    at HandlingScrollVertical.main(HandlingScrollVertical.java:33)

1 个答案:

答案 0 :(得分:0)

正如Arnaud在评论中指出的那样,它已声明为bug,并已由this pull request on Axium修复。

将您的appium-android-driver更新至最新版本应该可以解决此问题。