Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appium: "An element could not be located on the page using the given search parameters" error

I am new to Appium and have been trying to automate the Conversion Calculator app for Android. Am getting the error "org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters", when trying to find a EditText element. Using Appium ver 1.0.0 and Android 4.3

The following is my code:

List<WebElement> textViews = driver.findElements(By.className("android.widget.TextView"));
for (i=0; i<textViews.size(); i++) {
  if(textViews.get(i).getText().toLowerCase().contains("memory")) {
    textViews.get(i).click();
  }
} 
Thread.sleep(5000);

WebElement editText = driver.findElement(By.className("android.widget.EditText"));
editText.sendKeys("123");

Even findElement by ID is not working. Please let me know what I am doing wrong here or if I need to provide more details.

like image 876
Aby Avatar asked Aug 07 '14 10:08

Aby


2 Answers

I would use driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); instead of Thread.sleep(5000).

Try to use a newer version of Appium, I's been improved a lot. You can download the latest version of Appium and Appium clients here:http://appium.io/downloads.html

But be careful because in the newer version the findElement throws an Exception if there are more then one result of the search.


I would write this in a comment but I've not enough reputation :/

like image 153
stsatlantis Avatar answered Sep 30 '22 01:09

stsatlantis


Possible Cause:

  • Multiple EditText in the current screen.

Please try with the following:

Solution1:

List<WebElement> editText = driver.findElements(By.className("android.widget.EditText"));
editText.get(0).sendKeys("123");

0 - Index of EditText

Solution2:

Use any other locating strategy like Xpath.

like image 45
Abhishek Swain Avatar answered Sep 30 '22 03:09

Abhishek Swain