Unable to locate validation of android native app after many efforts in automation Unable to locate validation of android native app after many efforts in automation android android

Unable to locate validation of android native app after many efforts in automation


I have been doing Android App testing automation from last 2 years. I have encountered the same issue many times. Unfortunately, uiAutomator does not detect these kind of elements so we can't perform any actions on such elements.

Appium internally sends command to uiAutomator and uiAutomatar performs the actions on the device. uiAutomator can perform actions if uiAutomator sees those elements.

So I suggest you to don't spend much time on using java script or xPath because I have already tried hose solutions but none of them worked.

However, There is one solution which is very lengthy. You can take screen shot of this screen from the device and store it into your machine at run time and check whether that text "Invalid phone number." is available in the image using SIKULI. OR else you can ask developer to change the error message to some visible component in the uiAutomator. Hope this helps you.


Why don't try to search with regular expression such as:

public boolean IsValidationFired(){                  try{           WebElement invalid = driver.findElement(By.xpath("//*[@text='Invalid phone number.']"));           //You could check if @text contains just invalid Invalid           //WebElement invalid = driver.findElement(By.xpath("//*[contains(@text, 'Invalid')]]"));           if(invalid != null)           {               System.out.println("PASS");           }           else           {               System.out.println("FAIL");           }       }catch(NoSuchElementException ex){           System.out.println("Element not found");       }}

Anyway, this is not a really good solution (* at xpath)... Just use it to test. Searching will be slow... If you find the element you will have to make a better XPATH solution...

Note: After you find your element, to find out if is a TextView, Toast, ... I suggest to do this:

System.out.println(invalid.getAttribute("className"));//This will print something like: "android.widget.TextView"