Unable to click or select the button,text field

Friends,

Below is my code, the app launches when run,but its unable to select the button,gives an error as below:

Is it because i am using RemoteWebDriver instead of AndroidDriver?

Appium error log:

info: [debug] Responding to client with error: {“status”:7,“value”:{“message”:“An element could not be located on the page using the given search parameters.”,“origValue”:“Element was not found.”},“sessionId”:“633dd3fe-7233-eb66-8903-c63b69246cf0”}
info: ← POST /wd/hub/session/633dd3fe-7233-eb66-8903-c63b69246cf0/element 500 30181.879 ms - 201
info: → DELETE /wd/hub/session/633dd3fe-7233-eb66-8903-c63b69246cf0 {}
info: Shutting down appium session
info: [debug] Stopping selendroid server

Eclipse error log:

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: 30.19 seconds
For documentation on this error, please visit: Selenium
Build info: version: ‘2.48.2’, revision: ‘41bccdd’, time: ‘2015-10-09 19:59:20’
System info: host: ‘NCA1026471’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_66’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{app=C:\Appium\selendroid-test-app-0.17.0.apk, appPackage=io.selendroid.testapp, rotatable=true, networkConnectionEnabled=true, warnings={}, handlesAlerts=true, deviceName=Lokesh Gangaiah, version=0.17.0, platform=ANDROID, appActivity=io.selendroid.testapp.HomeScreenActivity, desired={app=C:\Appium\selendroid-test-app-0.17.0.apk, appPackage=io.selendroid.testapp, appActivity=io.selendroid.testapp.HomeScreenActivity, platformVersion=5.0, browserName=, platformName=Android, deviceName=Lokesh Gangaiah, device=Android}, acceptSslCerts=true, platformVersion=21, automationName=selendroid, browserName=selendroid, takesScreenshot=true, javascriptEnabled=true, platformName=android, device=Android}]
Session ID: 633dd3fe-7233-eb66-8903-c63b69246cf0

.java code:

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

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.mobile.*;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class testP1 {

public static RemoteWebDriver driver;
//public static AndroidDriver<MobileElement> driver;

@BeforeClass
public static void setUpBeforeClass() throws Exception {

	    File appDir = new File ("C:\\Appium\\");
	    //File app = new File (appDir,"CarsGuide com au_v1.0.8.1_apkpure.com.apk");
	    File app = new File (appDir,"selendroid-test-app-0.17.0.apk");
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("browserName", "");
		//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
		
		capabilities.setCapability("platformName", "Android");
		capabilities.setCapability("deviceName", "Lokesh Gangaiah");
		capabilities.setCapability("platformVersion", "5.0");
		capabilities.setCapability("device", "Android");
		
		capabilities.setCapability("app",app.getAbsolutePath());
		capabilities.setCapability("appPackage", "io.selendroid.testapp");
		capabilities.setCapability("appActivity", "io.selendroid.testapp.HomeScreenActivity");
		
		//capabilities.setCapability("appPackage", "au.com.carsguide");
		//capabilities.setCapability("appActivity", "au.com.carsguide.activity.HomeActivity");
		
		driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	
}

@Test
public void test() throws InterruptedException {
	
    System.out.println("Test Started");

    WebElement ButtonElement = driver.findElementById("io.selendroid.testapp:id/buttonStartWebview");
    ButtonElement.click();

    Thread.sleep(3000L);

    System.out.println("Test has been completed");
	
	//System.out.println("Hello2");
	
	//WebElement ButtonElement = 

// driver.findElement(By.id(“io.selendroid.testapp:id/showToastButton”)).click();
// System.out.println(“TEST2”);
//System.out.println(“Element” + ButtonElement.getText());
// ButtonElement.click();

// driver.findElementByName(“Search Cars for Sale”).click();
//By.id(“au.com.carsguide:id/search_btn”).findElement(driver).click();
Thread.sleep(1000L);

}

 @AfterClass
    public void tearDown()
    {
        driver.quit();
    }

}

I don’t think ID retrieves elements based on their resource IDs. Try searching for elements using their content descriptors instead with MobileBy.AccessibilityId.

Resource IDs can be retrieved using Xpath, e.g. //*[@resource-id='io.selendroid.testapp:id/buttonStartWebview'] but be sure to use Xpath tastefully.

1 Like

@afwang,thanks for the reply, i did try with content descriptors it worked fine now. But i still have other elements in the UI which does not have content descriptors , so what other elements should i be using? if no content desc