1

I’m unable to click on a particular element in a virtual device, using XPath to find the element.

This is the syntax I am using:

//tagname[@attribute='value']

Refer the code:

AndroidDriver<AndroidElement> driver=capability();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();

This is the error:

io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
    at io.appium.java_client.internal.ElementMap.getElementClass(ElementMap.java:77)
    at io.appium.java_client.internal.JsonToMobileElementConverter.newRemoteWebElement(JsonToMobileElementConverter.java:67)
    at org.openqa.selenium.remote.internal.JsonToWebElementConverter.apply(JsonToWebElementConverter.java:55)
    at io.appium.java_client.internal.JsonToMobileElementConverter.apply(JsonToMobileElementConverter.java:61)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:561)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
    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:428)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:151)
    at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
    at First.main(First.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 17 more
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • this is a very clear exception that any developer should be able to understand and fix. In the future when you see a stack trace like this, always look at the bottom-most "Caused by:..." and google the exception means. For now however I can tell you that you either are running your tests in a wrong way, or configured your dependency manager (maven? gradle?) in a wrong way and it has nothing to do with your xpath (which you still should not be using! it's the slowest kind of selector that is the most prone to error). – Kamil Janowski Jun 12 '20 at 04:59
  • So... let's start from the beginning. How do you start your test? Also, post the entire content of your pom.xml/build.gradle – Kamil Janowski Jun 12 '20 at 05:00
  • Hi Kamil, Have started my appium course recently, this is my first appium program Using API Demo app to auotmate Have invoked the app successfully but not able to click on particular element in the app So please help on this – Satish Kumar Jun 12 '20 at 06:10
  • your issue is not appium-specific. It's a very generic java error and like I said before, I cannot help you unless you show me exactly how you started the test (is it in some button in intellij? Or are you running some command in the terminal?) I also need to see what dependencies you have in your project, so assuming you use maven, please post the content of your pom.xml file. If you use gradle, I need the content of your build.gradle file. If you use neither... then you should start because otherwise you will not resolve your problem – Kamil Janowski Jun 12 '20 at 08:40
  • You're missing Apache commons-lang3 on your classpath. – Mark Rotteveel Jun 12 '20 at 09:02
  • Im not using either Maven or Gradle, Using jar files Java-client-7.3.0 jar and Appium client jars – Satish Kumar Jun 12 '20 at 09:02
  • Hi Kamil, Im not using either Maven or Gradle, Using jar files Java-client-7.3.0 jar and Appium client jars – Satish Kumar Jun 14 '20 at 04:46

0 Answers0