-1

I'm getting this error when trying to search for an element of a google calculator application

 mai. 07, 2023 9:18:47 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMAÇÕES: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {element-6066-11e4-a52e-4f735466cecf=00000000-0000-0213-ffff-ffff00000062, ELEMENT=00000000-0000-0213-ffff-ffff00000062}
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'DESKTOP-K81CURL', ip: '172.31.48.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.7'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
    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:402)
    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 br.ce.wcaquino.appium.CalculadoraTeste.main(CalculadoraTeste.java:31)
Caused by: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class org.openqa.selenium.WebElement (java.util.HashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.WebElement is in unnamed module of loader 'app')
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:361)
    ... 8 more

I've already tried to add the Selenium dependency but for now my pom.xml looks like this:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>br.ce.wcaquino.cursoAppium</groupId>
  <artifactId>cursoAppium</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies> 
      <dependency>
        <groupId>io.appium</groupId>
         <artifactId>java-client</artifactId>
         <version>5.0.4</version>
        </dependency>


  </dependencies>
  
</project>
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
HaiD
  • 1

1 Answers1

0

My code:


import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;



public class CalculadoraTeste {

    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("platformName", "Android");
        desiredCapabilities.setCapability("deviceName", "emulator");
        desiredCapabilities.setCapability("automationName", "uiautomator2");
        desiredCapabilities.setCapability("appPackage", "com.google.android.calculator"); //CASO NECESSARIO UTIULIZAR O APP PACKAGER MANAGER E PROCURAR PELO APPPACKAGE OU APPACTIVITY
        desiredCapabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
        desiredCapabilities.setCapability("noReset", "true");
        desiredCapabilities.setCapability("fullReset", "false");
        desiredCapabilities.setCapability("ensureWebviewsHavePages", true);
        desiredCapabilities.setCapability("nativeWebScreenshot", true);
        desiredCapabilities.setCapability("newCommandTimeout", 3600);
        desiredCapabilities.setCapability("connectHardwareKeyboard", true);
        
        AndroidDriver<MobileElement> driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
        
        MobileElement el3 = (MobileElement) driver.findElementByAccessibilityId("2");
        el3.click();
        MobileElement el4 = (MobileElement) driver.findElementByAccessibilityId("plus");
        el4.click();
        MobileElement el5 = (MobileElement) driver.findElementByAccessibilityId("2");
        el5.click();
        MobileElement el6 = (MobileElement) driver.findElementById("com.google.android.calculator:id/result_preview");
        el6.click();
    }
}
HaiD
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '23 at 09:39
  • Hi, how this can be an answer? Please edit original question, adding there all that. Read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Thank you – pierpy May 10 '23 at 11:09