Javascript 使用AppleScript单击safari网页按钮
我想知道如何点击网页上的按钮。例如,点击谷歌网页上的“我感到很幸运”按钮 这就是我尝试过的:Javascript 使用AppleScript单击safari网页按钮,javascript,html,safari,applescript,Javascript,Html,Safari,Applescript,我想知道如何点击网页上的按钮。例如,点击谷歌网页上的“我感到很幸运”按钮 这就是我尝试过的: tell application "Safari" make new document with properties {URL:"https://www.google.com/"} do JavaScript "eval(document.getElementById('I'm Feeling Lucky').parentNode.href.substring(11))" in do
tell application "Safari"
make new document with properties {URL:"https://www.google.com/"}
do JavaScript "eval(document.getElementById('I'm Feeling Lucky').parentNode.href.substring(11))" in document 1
delay 1
end tell
但它不起作用。你们中有人知道我如何使用applescript点击按钮吗
我非常感谢您的帮助以下几件事:
safari tell块中的最佳实践是也告诉文档1。另外,谷歌上那个按钮的ID是错误的。以下是页面中的代码:
<button class="gbqfba" aria-label="Google Search" id="gbqfba" name="btnK"><span id="gbqfsa">Google Search</span></button>
<button class="gbqfba" aria-label="I'm Feeling Lucky" onclick="google.x(this,function() {google.ifl && google.ifl.o();})" id="gbqfbb" name="btnI"><span id="gbqfsb">I'm Feeling Lucky</span></button>
在Chrome中执行相同操作的信息如下:
tell application "Safari"
activate
make new document with properties {URL:"https://www.yahoo.com/"}
delay 2
tell application "System Events"
keystroke "stackoverflow"
end tell
delay 0.3
tell document 1
do JavaScript "document.getElementById('search-submit').click();"
end tell
end tell