user2533604
user2533604

Reputation: 665

UIAutomation error in IOS

I am getting this error in automation script written for my application. Below is my script:

var testName = "Test 1";
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow(); 
window.textFields()[0].setValue("Hello");

In line 5 i am getting "cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().textFields()[0]".

what may be the reason for above error

Upvotes: 1

Views: 303

Answers (2)

fabe
fabe

Reputation: 718

As FenixAdar already told, the problem is that you want to access your textfield element through a non-existent hierarchy chain. To get the real hierarchy of the user interface elements you can insert the command target.logElementTree(); before the problematic row. Using the output of this command you will be able to guess the correct expression.

But even easier is to record with Instuments as you fill this textfield and check the generated code.

Upvotes: 0

FenixAdar
FenixAdar

Reputation: 47

This is because the textFields()[0] is nil.

the mainWindow method return a window, and the textFields() should in a UIViewController's view.

Upvotes: 1

Related Questions