Automation of the user interface: - How to press a button using a javascript screen that is not the main screen (iPhone)?

want to click a button through javascript for testing purpose. I can click the button that is on the first page, but has no idea how to click the button on the second page that appears after clicking the button on the first page.

+4
source share
2 answers

You just need a link to this button on the second page to repeat the process from the first page. You may have done something like this (this code from my application using the tab bar controller):

// Now tap the add button var navBar = mainWindow.navigationBar(); navBar.buttons()["Add"].tap(); // Now the app loads a new page // Get the nav bar again (it would have changed after the tap above) navBar = mainWindow.navigationBar(); 

So, the answer is simple - just return to the same functions, they will return everything on the screen at the moment.

+3
source

First you need to make sure the button is available. Or set the Accessability property in Interface Builder (Identity Inspector - the last tab) and give the button the appropriate accessibility label. If you are not using Interface Builder, you can set the property on the button programmatically.

Now in the script you can call

 mainWindow.buttons()["name of the accessability label"].tap(); 

mainwindow:

 var target = UIATarget.localTarget(); var application = target.frontMostApp(); var mainWindow = application.mainWindow(); 

Make sure the button is visible. The button should be the deepest element in the hierarchy of views that is marked as available. If the view containing the button is included as accessible, this will hide the availability of the button (which is a preview).

You can register all visible elements on the screen with

 mainwindow.logElementTree(); 

In addition, you can always use one single script. MainWindow.elements () refers to the view that is being displayed at a particular moment.

+1
source

Source: https://habr.com/ru/post/1339948/


All Articles