Search code examples
androiddynamicmenuappiumscreen-size

Appium : How to automate certain menu option which changes based on the screen size


Let say I have an mail button on the tool bar for certain certain document reader app. This mail appears on the tool bar for wider screen. But the same button on a device whose screen size is less, might show the mail as an option once clicking on the side menu options.

How would you automate such scenarios using appium?.

I am asking this question because the locator wouldn't be the same for button on the toolbar & an option in the menu.


Solution

  • I am assuming here that on different sizes of the screen there is an entirely different view of the said mail button i.e. there is no strategy (locator wise) which you can use.

    Assuming : mailBtnView1 is your element on toolbar and mailBtnView2 is your element on the menu option.

    I use a try-catch block in such cases. So, if mailBtnView1 is not present then catch the exception thrown and click mailBtnView2 e.g.

    try{
    mailBtnView1.click();
    }
    catch(NoSuchElementException e){mailBtnView2.click();}