How to element is visible in Mobile App using Appium driver

Method 1:-

        boolean displayed = wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("test 1"))).isDisplayed();

Method 2:-

driver.findElement(By.name(“test 1”).isDisplayed();

driver.getPageSource() returns element text “test 1” which is enabled and clickable as true at starting of the page. But “test 1” is visible at end of page.

Method 1 and Method 2 returns true when element “test 1” is not visible at staring of the page.

how can I proceed with this ?

1 Like

you can check any other attributes to make sure that it is on screen:

  • driver.findElement(By.name(“test 1”).getSize().getWidth()>0 + driver.findElement(By.name(“test 1”).getSize().getHeight()>0
  • driver.findElement(By.name(“test 1”).getLocation().getX()>0 and < width of screen + driver.findElement(By.name(“test 1”).getLocation().getY()>0 and < height of screen

maybe only some of mentioned will enough with your case

1 Like

@Aleksei Above method not working for me.

Its returns following

  1. driver.findElement(By.name(“test 1”).getSize().getWidth() => 48

  2. driver.findElement(By.name(“test 1”).getSize().getHeight() => 48

  3. driver.findElement(By.name(“test 1”).getLocation().getX()>0 and <
    width of screen => 60 > 0 && 60 < 1080
    => true

  4. driver.findElement(By.name(“test 1”).getLocation().getY()>0 and < height of screen => 6322 > 0 && 6322 < 1920
    => false

so:

  • width and height both are 48 = element have valid dimensions.
  • x is 60 = on screen, but y is 6322 <> on screen.

as result element outside screen.

did i understand correctly?

@Aleksei Yes You are right. How do I proceed now ?

just check that element Y is on screen > 0 and < screen width.