11

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.

Aby
  • 111
  • 1
  • 1
  • 4
  • `NoSuchElementException` usually occurs for a couple of reasons. 1. The element is inside of a `frame` or `iframe`. 2. The element is slow to load. – Richard Aug 07 '14 at 14:52

6 Answers6

6

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 :/

stsatlantis
  • 555
  • 9
  • 26
  • I have the same problem while using appium with protractor, shall i also add sleep(10000); for example ? i'm using the latest version of appium with ipad simulator in mac – Emna Ayadi Apr 14 '16 at 16:04
  • using the thread.sleep is not recommended, do you have any luck with the ```driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);``` approach? – stsatlantis Apr 20 '16 at 09:55
2

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.

Abhishek Swain
  • 1,054
  • 8
  • 28
1

Maybe you could try waiting until the element is visible or enabled using a WebDriverWait object?

Rusty Wizard
  • 531
  • 6
  • 20
1

In Appium v2 use

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
BraveEvidence
  • 53
  • 11
  • 45
  • 119
0

Avoid using sleep as much as possible, try using the WAIT command. Sleep without waiting for the time that has been determined, even if the element is already on the screen. In the case of the wait command, as soon as the element appears, the action will already be performed, this along the code will reduce the execution time considerably.

0

The issue for me was the app path I was using. If you are using a config file make sure to declare the application separately from the device.

If not, make sure the "app" capability has the right path. Here is the code in my config file for example:

devices_by_ids = {
    "platformName": "Android",
    "appium:DEVICE ADB ID": {
        "android_version": "13",
        "device_name": "google_Pixel_5a",
        "DEVICE ADB ID": "DEVICE ADB ID",
        "port":"4723",
        "autoGrantPermissions": "true",
    },
    "appium:app": "YOUR APP PATH",
    "appium:appWaitActivity": "*"
}
Antoine
  • 1,393
  • 4
  • 20
  • 26
Uzi Cohen
  • 1
  • 2
  • yes, I do see the issue is from 8 years ago, considering the issue still happens maybe this could help someone. – Uzi Cohen Nov 30 '22 at 06:51