Saurabh Bisht
Saurabh Bisht

Reputation: 408

UIAutomation script ios - deactivateAppForDuration throwing nil

When I run my automated script(UIautomation ios) in ios 9 ipad retina simulator then I get error at this line - deactivateAppForDuration(5); The code is :

 var target = UIATarget.localTarget();
 ......
 ......
 target.deactivateAppForDuration(5);

The error is :

[UIElementNil prepareForAction]...

Process : My app opens a link in safari and my application goes to background, now after 5 seconds I want to bring my application back to foreground.

Upvotes: 0

Views: 323

Answers (1)

Liliia
Liliia

Reputation: 79

The problem is the different UI layout on iOS9 (relatively to iOS7, iOS8), shown while you are trying to switch back to the app: https://forums.developer.apple.com/thread/19047

As you can see Apple knows the problem but not going to fix it. While trying to use function deactivateAppForDuration() for sending an application to BG for a while, it can not come back to FG and always throws the following exception:

-[UIAElementNil _prepareForAction:]: unrecognized selector sent to instance

As workaround I can suggest the following:

    try {
        UIATarget.localTarget().deactivateAppForDuration(time);
    } catch (error) {
        UIALogger.logMessage("Trying to perform workaround for iOS9");
        // here you are tapping almost to the screen center and coming back to the app as result
        UIATarget.localTarget().tap({origin:{x:35,y:140}, size:{width:99, height:70}});  
    }

Upvotes: 1

Related Questions