com.google.common.collect.Maps $ TransformedEntriesMap无法转换为org.openqa.selenium.WebElement

时间:2018-11-21 20:46:54

标签: appium appium-android

我有以下代码:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class SampleSauceCheckBoxTest {

    public static final String URL = "http://127.0.0.1:4723/wd/hub";
    public static AndroidDriver driver = null;

    public static void main(String[] args) throws Exception {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "6.0");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("app", "\\Users\\jsun\\Downloads\\app-debug.apk");

        driver = new AndroidDriver<>(new URL(URL), capabilities);

        /**
         * Test Actions here...
         */
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        MobileElement mbeLogin = (MobileElement)driver.findElementByXPath("//android.widget.Button[@content-desc='Log In']");
        mbeLogin.click();

        //driver.quit();
    }

}

以下是输出:

  

C:\ dev \ java \ jdk1.8.0_181 \ bin \ java.exe“ -javaagent:C:\ Program   文件\ JetBrains \ IntelliJ IDEA社区版   2018.2.4 \ lib \ idea_rt.jar = 57587:C:\ Program Files \ JetBrains \ IntelliJ IDEA社区版2018.2.4 \ bin“ -Dfile.encoding = UTF-8 -classpath   C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ charsets.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ deploy.jar; C:\ dev \ java \ jdk1.8.0 _181 \ jre \ lib \ ext \ access-bridge-64.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ cldrdata.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ dnsns.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ jaccess.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ jfxrt.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ localedata.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ nashorn.jar; C: \ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ sunec.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ sunjce_provider.jar; C:\ dev \ java \ jdk1 .8.0_181 \ jre \ lib \ ext \ sunmscapi.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ sunpkcs11.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ ext \ zipfs.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ javaws.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ jce.jar; C: \ dev \ java \ jdk1.8.0_181 \ jre \ lib \ jfr.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ jfxswt.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ jsse.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ management-agent.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ plugin .jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ resources.jar; C:\ dev \ java \ jdk1.8.0_181 \ jre \ lib \ rt.jar; C:\ work \ SauceLabsTest \ out \ production \ SauceLabsTest; C:\ work \ SauceLabsTest \ lib \ refined \ java-client-3.4.0.jar; C:\ work \ SauceLabsTest \ lib \ refined \ Selenium-server-standalone-3.4.0.jar   SampleSauceCheckBoxTest 2018年11月21日下午2:40:07   org.openqa.selenium.remote.ProtocolHandshake createSession INFO:   检测到的方言:线程“ main”中的W3C异常   org.openqa.selenium.WebDriverException:返回值不能为   转换为WebElement:{element-6066-11e4-a52e-4f735466cecf = 1}构建   信息:版本:“ 3.4.0”,修订版:“未知”,时间:“未知”系统   信息:主机:'L5480X2M2S5M2',ip:'10 .166.43.162',操作系统名称:'Windows   10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8.0_181'   驱动程序信息:driver.version:AndroidDriver位于   org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:417)     在   org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:509)     在   io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:132)     在   io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)     在   io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)在SampleSauceCheckBoxTest.main(SampleSauceCheckBoxTest.java:34)   造成原因:java.lang.ClassCastException:   com.google.common.collect.Maps $ TransformedEntriesMap无法转换为   org.openqa.selenium.WebElement位于   org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:415)     ...还有5个

     

以退出代码1完成的过程

该代码之前运行良好,所以这不是关于appium / selenium版本兼容性的问题。

1 个答案:

答案 0 :(得分:1)

从日志中,我了解到您需要使用类型为MobileElement的通用AndroidDriver。因此,在您的代码中将以下行更改为

AndroidDriver <MobileElement> driver = null;

还可以在查找元素时删除对MobileElement的转换。

编辑: 另外,请确保使用最新的Appium Java客户端和Selenium。