2012-01-18 40 views
18

我有一个使用UI自动化测试的iPhone应用程序。尝试使用UI自动化在UITableViewCell中点击UIButton失败,并显示“无法点击”

我在UITableViewCell中有一个按钮,但是当我尝试使用UI Automation轻触它时,出现以下错误。

Script threw an uncaught JavaScript error: target.frontMostApp().mainWindow().scrollViews()[0].elements()[element_name].tableViews()[0].elements().firstWithPredicate(name contains[c] 'Brooklyn').elements()["detailsButton"] could not be tapped 

我已经启用在界面生成器按钮可访问性和分配可访问的标签(和标识符)“detailsButton”。我可以检索按钮元素并验证它是有效的。我出于某种原因无法使用它。

UIATableCell Brooklyn

的的UIButton是与用户交互的圆矩形按钮启用。感谢您的任何反馈。

+0

您是否尝试过设置像target.delay(3)这样的延迟;在点击按钮之前? – 2012-04-10 13:47:00

+2

如何发布您的代码以及如何发布错误消息。 – 2012-07-19 04:38:22

+0

我认为这是一个关于如何将按钮添加到tableviewcell的问题 - 发布代码以获得更好的响应 – 2012-10-10 05:59:36

回答

1

您可以分配UIButton,除了使用圆形按钮。还可以在控制器类中设置表视图委托方法所呈现的按钮的目标操作。

0

你必须使用ButtonType=Custom

0
but=[UIButton buttonWithType:UIButtonTypeCustom]; 

您必须使用自定义按钮类型。

+2

你可能应该解释一些,而不仅仅是发布一行代码。 – Heskja 2012-10-20 10:34:22

0

我不知道你为什么使用UI自动化。但我知道关于在tableviewcell中添加UIButton-

1)只需在UITableViewCell中添加UIButton即可。
2)设置UIButton's标记值并将目标添加到该按钮。
3)在目标按钮方法,就可以得到UIButton对象,做你的东西在那里..

希望这有助于你出去。

1

尝试断言,如果按钮存在,使用tuneup_js轻松断言。 然后断言如果按钮被启用。

你试过了吗: target.frontMostApp().mainWindow().scrollViews()[0].elements()[element_name].tableViews()[0].**cells()**.firstWithPredicate("name contains[c] 'Brooklyn'").elements()["detailsButton"]

另外张贴另一张图片,其中显示了详细按钮存在的位置展开的UIATableCell。

-1

你试过吗?

target.frontMostApp().mainWindow().scrollViews()[0].tableViews()[0].elements().firstWithPredicate(name contains[c] 'Brooklyn').buttons()["detailsButton"].tap() 
0

我遇到了同样的问题。我添加延迟后,它的工作。

UIATarget.localTarget().delay(1); 
0

您可以在整个窗口调度点击事件:

function tap_from_window(elem) { 
    var mainWindow = target.frontMostApp().mainWindow(); 
    var elemRect = elem.rect(); 
    var windowRect = mainWindow.rect(); 

    var xPos = (20 + elemRect.origin.x)/windowRect.size.width; 
    var yPos = (50 + elemRect.origin.y)/windowRect.size.height; 

    mainWindow.tapWithOptions({tapOffset:{x:xPos, y:yPos}});  
} 

var target = UIATarget.localTarget(); 
var window = target.frontMostApp().mainWindow(); 
var tableView = window.scrollViews()[0].elements()[element_name].tableViews()[0]; 
tap_from_window(tableView.elements().firstWithPredicate(name contains[c] 'Brooklyn')) 

像一些相关的iOS的很多事情,我不知道为什么元素不能被直接轻击。我从这篇文章中的代码改编了上述函数:scrollToVisible error while testing on a device, UIAutomation