Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

android - Can we find element by ID in appium

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...