English 中文(简体)
iPhone UIAutomation button tap does not fire
原标题:

I am trying to use UIAutomation in Instruments with the iPhone Simulator and the latest iOS SDK 4.1. Here is the snippet of javascript that is having a problem:

// there are sufficient delays here to make sure the view is loaded
UIATarget.localTarget().frontMostApp().logElementTree();
main.buttons()["theButton"].tap();
UIALogger.logMessage("The button tapped");
for (var b = 0; b < main.buttons().length; b++)
{
    UIALogger.logMessage("Button title: " + main.buttons()[b].name());
}
main.toolbar().buttons()["OK"].tap();
UIALogger.logMessage("OK tapped");

The button name of "theButton" shows up in the logElementTree as well as showing up when I am logging the names of all the buttons, so it is correctly configured in the Interface Builder, but for some reason, it does not get tapped. I have other buttons earlier in the script that are getting tapped just fine, and if I abort the script at the point of the non-tapped button, I can click on the button in the Simulator and it works as expected.

EDIT: In the javascript for loop shown above, I had it tap each of the buttons in the main.buttons() array, and only 1 of the 12 identical buttons on the view gets the tap.

Also, in case you were wondering, I have this code at the top of the javascript file:

var target = UIATarget.localTarget();
var app = target.frontMostApp();
var main = app.mainWindow();

And here is the line that shows the button information from the sequence of entries that logElementTree puts into the log messages:

4) UIAButton [name:theButton value:(null) NSRect: {{25, 93}, {74, 74}}]
最佳回答

I had similar problem with tapping a button on an actionSheet. I m performing the scripts on the actual device. My code is:

//check that action sheet is on the screen
    app.actionSheetIsValid();

//check that the button is on the actionSheet
    actionSheet.actionSheetButton("Exit");

//touch Exit button
    actionSheet.tapActionSheetButtonByName("Exit");

All functions perform and pass, however the button is not pressed. logElementTree(); shows that the button is there.

I tried to add target.pushTimeout(5); after I check that the button is on the actionSheet in order to give it some time to detect and tap the button. This didn t help.

Then I added: target.delay(1); right after I check that the button is on the actionSheet and before tapping it. It helped in my case, the script is more robust and stable now.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签