Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we find element by ID in appium

Tags:

following link mentions that we can find element by giving id... but i am unable to find it.

https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/finding-elements.md

find by "name" (i.e., the text, label, or developer-generated ID a.k.a 'accessibilityIdentifier' of an element)

i tried following code:

WebElement el = driver.findElement(By.name("txtLogin")); 

where txtLogin is id for login button

it gives following exception:

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) 

can please anyone explain what are all the ways there to find elements in appium

like image 204
nilesh Avatar asked Mar 03 '14 08:03

nilesh


2 Answers

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"); 
like image 152
Mukul Avatar answered Sep 20 '22 19:09

Mukul


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

like image 29
anuja jain Avatar answered Sep 20 '22 19:09

anuja jain