Appium:Unable To Find Element

how to find element in appium android
locator strategies to identify an element in appium
appium find element by text
appium find all elements
appium cannot find element
appium desktop tutorial
appium webview
setwebcontentsdebuggingenabled appium

I have done Appium setup with Android Studio. I am able to launch app but unable to find element as a button or textview.

Here is my gradle file.

testImplementation 'junit:junit:4.10'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
implementation files('libs/byte-buddy-1.8.3.jar')
implementation files('libs/commons-codec-1.10.jar')
implementation files('libs/commons-exec-1.3.jar')
implementation files('libs/commons-logging-1.2.jar')
implementation files('libs/gson-2.8.2.jar')
implementation files('libs/guava-23.6-jre.jar')
implementation files('libs/httpclient-4.5.3.jar')
implementation files('libs/httpcore-4.4.6.jar')
implementation files('libs/okhttp-3.9.1.jar')
implementation files('libs/okio-1.13.0.jar')
implementation files('libs/client-combined-3.12.0-sources.jar')
implementation files('libs/client-combined-3.12.0.jar')
implementation files('libs/java-client-6.0.0.jar')   

Here is my test file.

RemoteWebDriver driver;
@Before
public void setup() throws MalformedURLException {

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("deviceName", "emulator-5554");
    caps.setCapability(CapabilityType.BROWSER_NAME, "Android");
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "8.0.0");// Pixel
    caps.setCapability("appPackage", "com.ebay.mobile");
    caps.setCapability("appActivity", "com.ebay.mobile.activities.MainActivity");

    // Instantiate Appium Driver
    try {
        driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
    } catch (MalformedURLException e) {
        System.out.println(e.getMessage());
    }
}
@Test
public void testIfEBaySearchAvailable() {

    driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);

    driver.findElement(By.name("SIGN IN")).click();
    driver.findElement(By.name("Search for anything")).click();
}  

}

Here is error which I am getting.

    F:\Android\Android_Setups\android-studio-ide-143.2790544-windows\android-studio\jre\bin\java -Didea.test.cyclic.buffer.size=1048576 -Didea.launcher.port=53087 -Didea.launcher.bin.path=F:\Android\Android_Setups\android-studio-ide-143.2790544-windows\android-studio\bin -Dfile.encoding=UTF-8 -classpath F:\Android\Android_Setups\android-studio-ide-143.2790544-windows\android-studio\lib\idea_rt.jar;F:\Android\Android_Setups\android-studio-ide-143.2790544-windows\android-studio\plugins\junit\lib\junit-rt.jar;F:\Android\Android_Setups\AndroidSdk\AndroidSdk\platforms\android-27\data\res;F:\Android\workspace\Appium_Assignment\app\build\intermediates\classes\test\debug;F:\Android\workspace\Appium_Assignment\app\build\intermediates\classes\debug;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-27.1.1.aar\97c0160fe173c1eb1e77c4b8fee42635\jars\classes.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\c905d0bd51dfa2168208e1142263aed1\res;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\c905d0bd51dfa2168208e1142263aed1\jars\classes.jar;C:\Users\sandy\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.1\860340562250678d1a344907ac75754e259cdb14\hamcrest-core-1.1.jar;F:\Android\workspace\Appium_Assignment\app\libs\byte-buddy-1.8.3.jar;C:\Users\sandy\.gradle\caches\modules-2\files-2.1\android.arch.core\common\1.1.0\8007981f7d7540d89cd18471b8e5dcd2b4f99167\common-1.1.0.jar;F:\Android\workspace\Appium_Assignment\app\libs\httpcore-4.4.6.jar;F:\Android\workspace\Appium_Assignment\app\libs\commons-codec-1.10.jar;F:\Android\workspace\Appium_Assignment\app\libs\commons-logging-1.2.jar;F:\Android\workspace\Appium_Assignment\app\libs\httpclient-4.5.3.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.0.aar\2ec91a3302209fd49d42034ca4133402\res;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.0.aar\2ec91a3302209fd49d42034ca4133402\jars\classes.jar;C:\Users\sandy\.gradle\caches\modules-2\files-2.1\com.android.support.constraint\constraint-layout-solver\1.1.0\931532e953a477f876f2de18c2e7f16eee01078f\constraint-layout-solver-1.1.0.jar;F:\Android\workspace\Appium_Assignment\app\libs\client-combined-3.12.0-sources.jar;F:\Android\workspace\Appium_Assignment\app\libs\commons-exec-1.3.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-vector-drawable-27.1.1.aar\da7d1cfef6afb9defe897425aa321eed\jars\classes.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\runtime-1.1.0.aar\cf9212e0fb1c62d642cd19dfeab937e0\jars\classes.jar;F:\Android\workspace\Appium_Assignment\app\libs\okhttp-3.9.1.jar;C:\Users\sandy\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common\1.1.0\edf3f7bfb84a7521d0599efa3b0113a0ee90f85\common-1.1.0.jar;C:\Users\sandy\.gradle\caches\modules-2\files-2.1\junit\junit\4.10\e4f1766ce7404a08f45d859fb9c226fc9e41a861\junit-4.10.jar;F:\Android\workspace\Appium_Assignment\app\libs\guava-23.6-jre.jar;F:\Android\workspace\Appium_Assignment\app\libs\java-client-6.0.0.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\90e51c77499731d2386df5f896a90684\jars\classes.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\90e51c77499731d2386df5f896a90684\res;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\730e0fd60e7316c1cd8988b484b608b6\res;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\730e0fd60e7316c1cd8988b484b608b6\jars\classes.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\viewmodel-1.1.0.aar\3eb742d286119fdd6f14adfe71e13ddd\jars\classes.jar;F:\Android\workspace\Appium_Assignment\app\libs\okio-1.13.0.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\livedata-core-1.1.0.aar\d107b006abfdde5437c7aa9690e097df\jars\classes.jar;F:\Android\workspace\Appium_Assignment\app\libs\gson-2.8.2.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-core-utils-27.1.1.aar\59acfae8dd42985675b0190ed39a72e9\jars\classes.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\support-fragment-27.1.1.aar\6987b3584a7fa4fc091439dfe90bd43e\jars\classes.jar;F:\Android\workspace\Appium_Assignment\app\libs\client-combined-3.12.0.jar;C:\Users\sandy\.gradle\caches\modules-2\files-2.1\com.android.support\support-annotations\27.1.1\39ded76b5e1ce1c5b2688e1d25cdc20ecee32007\support-annotations-27.1.1.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\runtime-1.1.0.aar\d027a275dfc22e0b4feb1e5305d6fd0a\jars\classes.jar;C:\Users\sandy\.gradle\caches\transforms-1\files-1.1\multidex-1.0.3.aar\f735cffb58b1a5290f5b402162f34341\jars\classes.jar;F:\Android\workspace\Appium_Assignment\app\build\intermediates\sourceFolderJavaResources\test\debug;F:\Android\workspace\Appium_Assignment\app\build\intermediates\sourceFolderJavaResources\debug;F:\Android\workspace\Appium_Assignment\app\build\generated\mockable-android-27.v3.jar com.intellij.rt.execution.application.AppMainV2 com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 sandy.com.appium_assignment.EBayAppiumTest,testIfEBaySearchAvailable
Jun 02, 2018 5:14:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS

   org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {error=invalid selector, message=Locator Strategy 'name' is not supported for this session, stacktrace=InvalidSelectorError: Locator Strategy 'name' is not supported for this session
    at AndroidDriver.validateLocatorStrategy (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\basedriver\driver.js:328:13)
    at AndroidDriver.callee$0$0$ (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\basedriver\commands\find.js:19:8)
    at tryCatch (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at invoke (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:136:37)
    at enqueueResult (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:185:17)
    at new Promise (<anonymous>)
    at new F (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\core-js\library\modules\$.export.js:30:36)
    at AsyncIterator.enqueue (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:184:12)
    at AsyncIterator.prototype.(anonymous function) [as next] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at Object.runtime.async (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:209:12)
    at AndroidDriver.callee$0$0 [as findElOrElsWithProcessing] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\build\lib\basedriver\commands\find.js:35:30)
    at AndroidDriver.callee$0$0$ (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\basedriver\commands\find.js:35:21)
    at tryCatch (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at invoke (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:136:37)
    at enqueueResult (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:185:17)
    at new Promise (<anonymous>)
    at new F (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\core-js\library\modules\$.export.js:30:36)
    at AsyncIterator.enqueue (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:184:12)
    at AsyncIterator.prototype.(anonymous function) [as next] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at Object.runtime.async (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\babel-runtime\regenerator\runtime.js:209:12)
    at AndroidDriver.callee$0$0 [as findElement] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\build\lib\basedriver\commands\find.js:76:30)
    at C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\basedriver\driver.js:275:26
    at tryCatcher (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\util.js:26:23)
    at Promise._settlePromiseFromHandler (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\promise.js:510:31)
    at Promise._settlePromiseAt (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\promise.js:584:18)
    at Promise._settlePromiseAtPostResolution (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\promise.js:248:10)
    at Async._drainQueue (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\async.js:128:12)
    at Async._drainQueues (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\sandy\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\node_modules\bluebird\js\main\async.js:15:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)}
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'DESKTOP-A5G86II', ip: '192.168.0.104', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_152-release'
Driver info: driver.version: RemoteWebDriver

    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:324)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:395)
    at org.openqa.selenium.By$ByName.findElement(By.java:284)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:309)
    at sandy.com.appium_assignment.EBayAppiumTest.testIfEBaySearchAvailable(EBayAppiumTest.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
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:322)
    ... 33 more


Process finished with exit code -1   

I am able to launch app but mu test case getting fail with above error.

Here is screenshot from uiautomatorviewer

Not able to find elements using any locators for my , Hello , I am not able find elements of my mobile app either from ID,X-PATH or classname getting below exception attached screenshot of code and app elements  # ruby_lib example find_element(:accessibility_id, 'SomeAccessibilityID') # ruby_lib_core example @driver.find_element(:accessibility_id, 'SomeAccessibilityID')

By.name() doesn't work, try with findElementByAndroidUIAutomator:

public WebElement scrollByTextTo(String desc) {
    return driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
        ".scrollIntoView(new UiSelector().text(" + "\"" + desc + "\"" + "));");
}

Unable to find element - Support, Hi Team, i am unable to find element in side a frame layout . Could you please help me on this. I tried many options like xpath ,accessibility id  @mykola-mokhnach, Thanks. Yes, I have tried at Appium 1.6.0 and Appium 1.5.2. all met the same as issue. Issue: can initialize the Android driver, but run cases very slowly, andCANNOT find the element.

Locating an element on mobile screen with appium don't work any more with strategy By.name("-----").

you can use 'resource-id' which as locator which is displayed in your uiautomator viewer screen. so you can use something like for 'Sign In' click

   driver.findElement(By.id("com.ebay.mobile:id/button_sign_in")).click();

OR by using XPATH

 driver.findElement(By.xpath("//android.widget.Button[text()='SIGN IN']")).click();

You can use similar strategy for 'Search for Anything' element.

Unable to locate elements in android app for login , Hi, I am new to Appium automation. I am stuck right now with identifying the elements of login page. The app which I am testing is available in  appium 1.1.0, android 4.3, java-client 1.3 I have an element with content-desc property set to "abc". if I use AppiumDriver.FindElementById(), i get error: Could not find an element using supplied strategy.

NoSuchELementException when element is , NoSuchElementException: Can't locate an element by this strategy: if you fail to find your element with this check element attributes with  Either Appium Inspector or tests run by Appium cannot find element placed inside GridView. It concerns just Android and just emulator. On Android device it works fine. Using uiautomatorviewer tool can localise that element and give me some details about it, so my element is there.

Unable to find element using xpath, ID, name on , Hi All, I'am setup automation testing on Mobile using Appium and I got the issue regarding to find element on Android apps. I couldn't find  Ah. Ok, it is just parsing the XML, then. The getAttribute method queries the device for the information, and the device does allow us to check for password. It seems like you'll have to get the source and find your element in there.

Cannot Find Element - Issues/Bugs, I have tried find element by class name, identifier, xpath, and accessibility label id","value":"home_carousel_2","description":"unable to find an  Using Appium Desktop To Locate Elements Appium provides you with a neat tool that allows you to find the the elements you're looking for. With Appium Desktop you can find any element and its locators by either clicking the element on the screenshot image, or locating it in the source tree.

Comments
  • You can try by suing xpath like driver.findElement(By.xpath("//*[@text='SIGN IN']")).click(); or by text like driver.findElement(new By.ByName("SIGN IN")).click();
  • I tried all way to find element.
  • can you add the screenshot with UIAutomatorViewer ?
  • @AlImran added snapshot. Please check
  • Have you tried with element ID? button_sign_in
  • Why did you mention By.xpath as bad option? At least in Selenium By.xpath is same stable and fast as By.cssSelector
  • Because Appium is not Selenium, they just share the same concept of JSON Wire protocol. XPath is not native locator strategy so it requires an additional step to prepare XML representation of app screen and then search by provided XPath.