Sta*_*han 5 javascript applescript getelementbyid
我的目标是确定元素是否在页面上并对该元素执行操作(如果存在).
在这段代码中,我只展示了尝试对元素执行操作的第二部分.
我的代码是:
tell application "Safari"
open location "http://www.apple.com"
tell front document
do JavaScript "document.getElementById(\"gn-store\").click()"
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
但是,我总是得到一个"缺失值"的结果,从这个代码和我尝试过的类似的事情(包括在Js中调用一个函数,从getElementById()返回一个值.
我不明白我做错了什么.我已经好几个小时了.(并且为了记录,我是一个苹果菜菜鸟).
我发现 Chrome 通过 AppleScript 对 Javascript 的反应更好...
tell application "Google Chrome"
if not (exists window 1) then reopen
activate
tell window 1 to tell active tab
set its URL to "http://www.apple.com/"
delay 3
execute javascript "document.getElementById('gn-store').childNodes[0].click()"
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6305 次 |
| 最近记录: |