Can we find element by ID in appium Can we find element by ID in appium android android

Can we find element by ID in appium


You can use element ID as following:-

package name : com.example.testap

Element ID : txtLogin

write the following code -

 driver.findElement(By.id("com.example.testapp:id/txtLogin")).sendKeys("abc");


Here is the jave code with most common ways to locate elements using Appium

//Find element by id and enter Hello in Text box.    driver.findElementById("edit_name").sendKeys("Hello");    //Find element by class name and enter Hello in Text box.     driver.findElementByClassName("com.android.EditText").sendKeys("Hello");    //Find element by xpath and enter Hello in Text box.    driver.findElementByXPath("//cass[@value='Enter Name']").sendKeys("Hello");    //Find element by link text and enter Hello in Text box.    driver.findElementByLinkText("Enter Name").sendKeys("Hello");

If you want to learn more ways to find elements in appium for native and webviews VISIT HERE


You can find by id using Xpath too,e.g.enter image description herehere element has class="android.widget.Button" and id="digit5" so you can find like

xpath("//android.widget.Button[contains(@resource-id,'digit5')]")

Xpath is most useful when you want apply Multiple condition likexpath("//android.widget.Button[contains(@resource-id,'digit5') and @text='5']")for more details you can see on http://www.software-testing-tutorials-automation.com/2015/10/ui-automator-viewer-get-android-app.html