首页 > 解决方案 > 使用 JavaScript document.getElementById 方法的结果“缺失值”

问题描述

我正在尝试自动化搜索并关注计算机在搜索栏中搜索的部分。我认为我所有的语法都是正确的,但是当我运行代码时,什么也没有发生,并且在 applescript 结果日志中它说“缺少值”..

这是我的代码:

to inputByID(theId, theValue) --defines the function--
    tell application "Google Chrome"
        open location "https://www.google.com "
        execute javascript " document.getElementById(' " & theId & " ').value = ' " & theValue
    end tell
end inputByID

inputByID("lst-ib", "hi ")

我的语法错误还是我遗漏了什么?任何帮助表示赞赏..

标签: javascriptapplescript

解决方案


" document.getElementById('" & theId & "').value = '" & theValue & "'"

可能你必须删除前后的空格theId

这样它就变成('myId')(' myId ')

并在末尾添加报价。


推荐阅读