noSuchElementException in Amazon Device Farm

Hello

I´ve run a sucessful test for an iPar Air 2 from chosen from the Amazon device farm. Then I run the same test after selecting iPhone 5s from Amazon device farm and it fails. The error message says “noSuchElementException”. The test is written in Java, and Both devices have iOS 10.2.
Does somebody know why is this happening?

Thanks.

Different versions of devices can have different UI’s, and sometimes the same selector will not work.

Unless there’s an underlying bug or misconfiguration, the answer is going to be tweaking your selector. Are you using XCUITest, and if so, are predicates your selector method?

You could post the selector here, but most likely you will just need to inspect the UI of your app, and craft a selector that will work on both platforms.

Also, make sure the app is open, and that other parts of the Appium connection are working fine.

Kind regards, and hope this helps.

Thank you for your answer, Emil.

I am using is XCUITest, and my selector method is:
WebElement alert = driver.findElement(By.className(“UIAAlert”));
So should I to assert that the class UIAAlert is not suitable for an iphone? Then How cani I reffer to an UIAAlert object on an iphone device?

Greetings.

Hi Paco7778,

If you are able to find more details about the object, I suspect you will have a better chance of success.

Here is an example of crafting a complex predicate: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios_predicate.md

Are you certain that the element appears on the current page? You can do something comparable to (this python example:
logging.debug(driver.page_source())

There will be some Java equivalent I’m sure, and this will allow you to confirm which page Appium thinks it’s one, and help you both make sure it contains the element you’re trying to select, and give you the details of what fields the element has.

Are you watching the screen? One thing I found in testing is that smaller errors can lead to issues like this by, say, an attempt to switch pages in the app failing.

Good luck.

why is this marked as news?

Can you please share the page source? As your device ios 10 above so the locator strategy no more use UI Automation.

You should try something like:

WebElement alert = driver.findElement(By.className(“XCUIElementTypeAlert”));

The issue goes on with “XCUIElementTypeAlert”. It works for ipad but not for iphone.

My page source is
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**

  • Created by appium on 13/3/17.
    */
    public class appiumTest {

    //private RemoteWebDriver driver;

    // public AppiumDriver driver;

    private AppiumDriver driver;

    private List values;

    public WebDriverWait wait ;
    @Before
    public void setup() throws MalformedURLException{
    DesiredCapabilities desiredCapabilities;

     desiredCapabilities = new DesiredCapabilities();
    
     desiredCapabilities.setCapability("deviceName","IPad Air2");
     //desiredCapabilities.setCapability("deviceName","iPhone 5s");
     desiredCapabilities.setCapability("udid","07436359a6f86dce57b77a0b941b92d6975e3480");
    
     //desiredCapabilities.setCapability("udid","2E611BE3-7495-4BFE-A288-EB24BFC828CC");
    
     desiredCapabilities.setCapability("platformVersion","10.2.1");
     desiredCapabilities.setCapability("appiumVersion","v1.6.0");
     desiredCapabilities.setCapability("platformName","iOS");
     //desiredCapabilities.setCapability("orientation","LANDSCAPE");
     desiredCapabilities.setCapability("automationName","XCUITest");
     desiredCapabilities.setCapability("xcodeOrgId","DXKN9UUK5Q");
     desiredCapabilities.setCapability("xcodeSigningId","iPhone Developer");
     //desiredCapabilities.setCapability("automationName","UIautomation");
     //requiredcapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.iOS);
     //requiredcapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Ipad Air2 Device");
     desiredCapabilities.setCapability("app","/Users/appium/Documents/PruebaAppium_old.ipa");
     desiredCapabilities.setCapability("realDeviceLogger","/usr/local/lib/node_modules/deviceconsole/deviceconsole");
    
     //driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"),desiredCapabilities);
      driver = new IOSDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),desiredCapabilities);
    
     //driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),desiredCapabilities){};
     wait=new WebDriverWait(driver,60);
    

    }

    @After
    public void tearDown() throws Exception{
    driver.quit();
    }

    @Test
    public void selectLoginWithEmail() {

     List<WebElement> elems = driver.findElements(By.className("UIATextField"));
     for (WebElement elem : elems) {
         elem.sendKeys("trytryte");
     }
    
     //WebElement cajaCorreo = driver.findElement(By.name("Email"));
     WebElement cajaCorreo = driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]"));
     cajaCorreo.sendKeys("correo");
    
     WebElement button = driver.findElement(By.className("UIAButton"));
     button.click();
    
    
     //WebElement texto =driver.findElement(By.className("UIAAlert"));
     WebElement texto = driver.findElement(By.className("XCUIElementTypeAlert"));
     String texto2 = texto.getAttribute("label");
     System.out.print(texto2);
    
     Assert.assertTrue("Correcto",texto2.equalsIgnoreCase("Login KO"));
    
    
     //try {
     //    Thread.sleep(55000);
     //} catch (InterruptedException e) {
     //}
    

    }
    }

An the error message Amazon returns is:

selectLoginWithEmail failed: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 910 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘2.48.2’, revision: ‘41bccdd10cf2c0560f637404c2d96164b67d9d67’, time: ‘2015-10-09 13:08:06’ System info: host: ‘ip-172-31-13-65’, ip: ‘172.31.13.65’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.13.0-53-generic’, java.version: ‘1.8.0_65’ Driver info: io.appium.java_client.ios.IOSDriver Capabilities [{app=com.ibermatica.PruebaAppium, networkConnectionEnabled=false, appiumVersion=v1.6.0, xcodeOrgId=DXKN9UUK5Q, databaseEnabled=false, deviceName=IPad Air2, xcodeSigningId=iPhone Developer, platform=MAC, realDeviceLogger=/usr/local/lib/node_modules/deviceconsole/deviceconsole, platformVersion=10.2.1, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=iOS, udid=278d7a1371d7a4fc9e2eb0b4639c70969e0eaaa3}] Session ID: 55054aef-5092-4d0a-a77b-8c0eb3ae2205 *** Element info: {Using=class name, value=XCUIElementTypeAlert}

Any help would be appreciated.

1 Like

On a failure like this I will often do a driver.getPageSource. You could do this before the call that fails and then see what is in the screen. I’m suspecting that this might be a good use case for an implicit wait, but not entirely sure.

http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

Hello
The issue has been fixed by rewitting the app code in such a way that all the text boxes, and the login button appear into the device´screen, for ipad as much as iphone.
Thank you very much for your suggestions.