Hello. I am new on appium and I’ve spotted problem I am unable to deal with.
I am practiing appium on ApiDemos-debug.apk delivered by Android developers I believe.
This is my code:
package tutorial;
import io.appium.java_client.android.*;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.TouchAction;
public class gestures extends base {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
AndroidDriver<AndroidElement> driver = Capabilities();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //manage waits? use INSTEAD of thread.sleep(SECONDS);
//enter Views tab
driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
//Tap action. Create new class object and import appropriate library
TouchAction touch = new TouchAction(driver);
//actual tapping
//alternatively: touch.tap(driver.findElementByXPath("(//android.widget.TextView)[10]")).perform();
touch.tap(driver.findElementByXPath("//android.widget.TextView[@text='Expandable Lists']")).perform();
touch.tap(driver.findElementByXPath("//android.widget.TextView[@text='1. Custom Adapter']")).perform();
}
}
Everything is ok to the almost line:
touch.tap(driver.findElementByXPath("//android.widget.TextView[@text='Expandable Lists']")).perform();
Program enters “Expandable Lists” but the next line fails:
touch.tap(driver.findElementByXPath("//android.widget.TextView[@text='1. Custom Adapter']")).perform();
Console log:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11.54 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-7Q1276D', ip: '172.16.5.147', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=C:\Users\Konrad\workspace\ApiDemos\src\tutorial\ApiDemos-debug.apk, appPackage=io.appium.android.apis, deviceScreenSize=1200x1920, networkConnectionEnabled=true, warnings={}, appWaitPackage=io.appium.android.apis, appWaitActivity=io.appium.android.apis.ApiDemos, databaseEnabled=false, deviceName=CB5A2370B9, platform=LINUX, deviceUDID=CB5A2370B9, appActivity=io.appium.android.apis.ApiDemos, desired={app=C:\Users\Konrad\workspace\ApiDemos\src\tutorial\ApiDemos-debug.apk, platformName=Android, deviceName=CB5A2370B9}, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, deviceModel=SGP611, platformName=Android, deviceManufacturer=Sony}]
Session ID: 4da5db73-75b2-435b-a0fa-d16305b6e733
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.PerformsTouchActions.performTouchAction(PerformsTouchActions.java:39)
at io.appium.java_client.TouchAction.perform(TouchAction.java:381)
at tutorial.gestures.main(gestures.java:26)
Why and how? These two lines are almost the same, only name is different… I would appreciate solution and/or some materials to read about this.
@edit
base class only sets up capabilities and driver.
Greetings.