Find element() is not able to recognize click() command!

hello,

My script doesnt recognize click() command if i use
driver.findElement(By.id(“com.mobeta.android.demodslv:id/activity_title”)).get(0).click();

but If i use driver.findElementByAndroidUIAutomator class its able to detect the click() command,can any body tell me the solution so even findelement is able to detect click() command

Here is my script:

package com.appium.mobile.mobilegestures;

import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

public class DragAndDrop {

@Test

public void testDragDrop() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities() ;
capabilities.setCapability(“automationName”,“Appium”);
capabilities.setCapability(“platformnName”,“Android”);
capabilities.setCapability(“platformVersion”,“5.1.1”);
capabilities.setCapability(“deviceName”,“Nexus 6” );
capabilities.setCapability(“app”,“C:\Users\Jenny\Downloads\demodslv.apk”);
capabilities.setCapability(“appPackage”,“com.mobeta.android.demodslv”);
capabilities.setCapability(“appActivity”, “Launcher”);
AndroidDriver driver = new AndroidDriver (new URL (“http://127.0.0.1:4723/wd/hub”), capabilities) ;
driver.manage().timeouts().implicitlyWait(160,TimeUnit.SECONDS);

driver.findElement(By.id("com.mobeta.android.demodslv:id/activity_title")).get(0).click();

}

}

Junit throws error that not able to recogize click() command

It should work
driver.findElement(By.id(“com.mobeta.android.demodslv:id/activity_title”)).click();

get(index) is a List Class method
Returns the element at the specified position in this list

Since below command returns only 1 element so no need of getting index, direct click should work
driver.findElement(By.id(“com.mobeta.android.demodslv:id/activity_title”))

Hi thanks,
It works :slight_smile: