-1

I am using java with appium. I executed my code using 2 ways. One -when I am using below code it is working fine.

public class On_BoardingPages

    MobileElement smsField = driver.findElement(By.id("pinEntryViewVerifyCode"));
    smsField.sendKeys("XXXX");


    public On_BoardingPages(AppiumDriver<MobileElement> driver) {
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);

    }
    public void enterSMSVerificationCode(String codeVerification) { 
        sms_VerificationCode.sendKeys(codeVerification);

    }

Second- When I am using POM and its failing

page class:

@FindBy(id = "pinEntryViewVerifyCode")
private MobileElement sms_VerificationCode;

TestClass

on_BoardingPages.enterSMSVerificationCode("XXXX");

Error:

org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: By.chained({By.id: pinEntryViewVerifyCode}) at io.appium.java_client.pagefactory.AppiumElementLocator.findElement(AppiumElementLocator.java:126) at io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.intercept(InterceptorOfASingleElement.java:60) --Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for io.appium.java_client.pagefactory.AppiumElementLocator$WaitingFunction@56a4479a (tried for 1 second(s) with 500 milliseconds interval) at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:303) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271) at io.appium.java_client.pagefactory.AppiumElementLocator.waitFor(AppiumElementLocator.java:99) at io.appium.java_client.pagefactory.AppiumElementLocator.findElement(AppiumElementLocator.java:119)

Saddam Abu Ghaida
  • 6,381
  • 2
  • 22
  • 29
Tester
  • 51
  • 1
  • 12

1 Answers1

0

@FindBy will work only for WebElements POM. For MobileElements we should use @AndroidFindBy for android and @iOSXCUITFindBy for iOS.

So your code will look like:

@AndroidFindBy(id = "pinEntryViewVerifyCode")
private MobileElement sms_VerificationCode;
Sooraj
  • 565
  • 3
  • 8
  • 1
    You can also set a breakpoint where the test is failing and use the "Evaluate Expression" command `(alt + f8)` to check whether or not `driver.findElement(MobileBy.id("pinEntryViewVerifyCode"));` will work – Mark Han Dec 20 '19 at 17:06
  • Yes it worked with find by, but I used @androidFindBy because its an android element.Issue was wait here – Tester Dec 23 '19 at 23:35