import java.net.MalformedURLException;
import org.openqa.selenium.By;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class gf extends jo{
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver=capabilities();
driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
//Tap
TouchAction t =new TouchAction(driver);
t.tap(driver.findElementByXPath("//android.widget.TextView[@text='Expandable Lists']")).perform();
driver.findElementByXPath("//android.widget.TextView[@text='1. Custom Adapter']").click();
t.press(driver.findElement(By.xpath("//android.widget.TextView[@text='People Names']"))).waitAction(3000).release().perform();
//t.press(driver.findElementByXPath("//android.widget.TextView[@text=‘People Names’]")).waitAction(3000).release().perform();
System.out.println(driver.findElementById(“android:id/alertTitle”).getText());
//
// Tap, Press and release,scroll,Swipe, drap and drop
This is the extends jo file. Which is your base file
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class jo {
public static AndroidDriver<AndroidElement> capabilities() throws MalformedURLException
{
File f=new File("src");
File fs=new File(f,"ApiDemos-debug.apk");
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "JeromePhone");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
AndroidDriver<AndroidElement> driver=new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
return driver;
}
}
I am getting this error:
Sep 08, 2018 9:49:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread “main” org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {element-6066-11e4-a52e-4f735466cecf=1}
Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: '2018-08-02T20:13:22.693Z’
System info: host: ‘Jeromes-MacBook-Air.local’, ip: ‘2601:c6:4101:b20:fd41:c5d3:3a1:2487%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.13.2’, java.version: '1.8.0_161’
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:329)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:56)
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.findElementByXPath(RemoteWebDriver.java:424)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:134)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at gf.main(gf.java:15)
Caused by: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to org.openqa.selenium.WebElement
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:327)
… 8 more