Search code examples
seleniumautomated-testsappiumappium-android

Using both .isDisplayed and .isEnabled?


Intro: I'm making automated tests with appium and I'm fairly new to it. Newbie question: Is there any point making double assertions for elements using is.Displayed and .isEnabled?


Solution

  • Assertion .isEnabled means that the element is not disabled, to clarify this here is sample code:

    <!DOCTYPE html>
    <html>
    <body>
    
    <form action="/action_page.php">
      Enabled: <input type="text" name="fname"><br>
      Disabled: <input type="text" name="lname" disabled><br>
      <input type="submit" value="Submit">
    </form>
    
    </body>
    </html>

    First input is enabled and second is disabled, but both of them are displayed. But it could be also like this:

    <!DOCTYPE html>
    <html>
    <body>
    
    <form action="/action_page.php">
      Not displayed and enabled: <input type="text" name="fname" style = "display: none"><br>
      Displayed and enabled: <input type="text" name="fname" style = "display: inline-block"><br>
      Not displayed and disabled: <input type="text" name="lname" disabled style = "display: none"><br>
      Displayed and disabled: <input type="text" name="lname" disabled style = "display: inline-block"><br>
      <input type="submit" value="Submit">
    </form>
    
    </body>
    </html>

    Therefore there are different assertions for Selenium for different test cases. If you want a combination of both .isDisplayed and .isEnabled, use .elementToBeClickable. More information in documentation(JAVA)