1

我们可以使用 JavaScript 向 Cocoa 应用程序中的 webview 内的按钮发送点击事件吗?

我正在尝试使用实用程序(优胜美地)下的脚本编辑器进行记录,但不幸的是无法记录 webview 中的任何事件。

我尝试使用 Apple 文档中提供的 UI 自动化部分下的示例代码与https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html的 testapp(带有 webview 的可可应用程序).

TestApp = Application('TestApp')    
TestApp.activate()

delay(1)

SystemEvents = Application('System Events')

TestApp = SystemEvents.processes['TestApp']

TestApp.document.getElementById('testid').click();      // stuck at this last line not sure if I can    
//even call the document object in this way. Getting error undefined variable document.
4

1 回答 1

0

您正在尝试使用浏览器/DOM Javascript 来访问本机应用程序 UI 元素。尽管此环境像浏览器一样使用 Javascript,但底层对象模型并不是您习惯在网页上看到的 DOM。这就是为什么您看到document未定义的原因。

正如文档“UI 自动化”部分中的小片段所暗示的那样,您需要访问窗口和按钮对象。当然,您将使用的确切路径取决于您的 TestApp,但它可能类似于:

TestApp.windows[0].buttons[0].click()

(可能也可以通过控件 ID 使用 或类似方法来遍历这些数组whose,但没有这方面的经验。)

于 2014-11-22T01:50:02.360 回答