I am new to Appium and was trying on android device, so while writing code I want to use Android Driver but everytime error comes up, check the error below
"Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=1} Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'DESKTOP-HT0VM72', ip: '192.168.88.104', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_144' Driver info: driver.version: AndroidDriver at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:417) 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.findElementByName(RemoteWebDriver.java:485) at io.appium.java_client.DefaultGenericMobileDriver.findElementByName(DefaultGenericMobileDriver.java:110) at io.appium.java_client.AppiumDriver.findElementByName(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.findElementByName(AndroidDriver.java:1) at org.openqa.selenium.By$ByName.findElement(By.java:303) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1) at demo.TestCase1.main(TestCase1.java:31) Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:415) ... 13 more"
but if i replace AndroidDriver with RemoveWebDriver it works fine? why? "Appium version 1.4.16.1 (Ophiuchus)"
package demo;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.android.AndroidDriver;
public class TestCase1 {
public static void main(String[] args) throws MalformedURLException {
RemoteWebDriver driver;
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("deviceName", "Fever 4G");
cap.setCapability("platformVersion", "6.0");
cap.setCapability("platformName", "Android");
cap.setCapability("appPackage", "com.vector.guru99");
cap.setCapability("appActivity", "com.vector.guru99.BaseActivity");
driver =new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//verification1
if(driver.findElement(By.name("Guru99")).isDisplayed())
System.out.println("guru99 header is displayed");
else
System.out.println("guru99 is not displayed");
//verification2
if(driver.findElement(By.name("Course Category")).isSelected())
System.out.println("Course category is currently selected");
else
System.out.println("Course Category is not selected");
//Get all the courses listed in the course category
List<WebElement> courseoffered=driver.findElements(By.id("com.vector.guru99:id/lblListHeader"));
System.out.println("Course offered are :");
for(WebElement course : courseoffered)
{
String cours= course.getText();
System.out.println(cours);
if(course.isEnabled())
System.out.println(" is Enabled ");
else
System.out.println(" is not Enabled");
}
driver.quit();
}
}