Unable to execute Isdisplayed() method

Hi,
I am stuck at a very important part of my automation which i am unable to resolve.

I wanted to execute below code which indicates that:

/if modal is displayed/
if(driver.findElement(By.xpath("//android.widget.FrameLayout[1]//android.widget.FrameLayout[1]//android.widget.FrameLayout[1]//android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]")).isDisplayed())
{
/click yes/
driver.findElement(By.xpath("//android.widget.FrameLayout[1]//android.widget.FrameLayout[1]//android.widget.FrameLayout[1]//android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.Button[1]")).click();
}
else
{
/else click back/
driver.findElement(By.xpath("//android.view.View[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.widget.ImageButton[1]")).click();
}

The problem is that, Appium is not identifying/considering isDisplayed() method, stucks on “if” clause and starts searching for the modal and the time out occurs and it doesn’t go to next step at all.

I have also tried to use below “size” method instead of “isDisplayed”, but eclipse not accepting “size” method.
if(driver.findElement(By.xpath("//android.widget.FrameLayout[1]//android.widget.FrameLayout[1]//android.widget.FrameLayout[1]//android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]")).size()>0)

Environment:

  • Appium version: 1.4.16
  • Eclipse version: eclipse_Kelper64

Please suggest.
Thanks in advance

I have found the below solution with the help of my senior developer and now my whole scenario is working perfect. I thought i must have to share this here, so that anyone can take benefit from the following solution of above mentioned problem.

WebDriverWait driverWait = new WebDriverWait(driver, 3);
try {
if(driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“btnOk”))) != null){
driver.findElement(By.id(“btnOk”)).click();
}
}
catch(Exception e) {
driver.findElement(By.id(“btnCancel”)).click();
}

Thanks :slightly_smiling: