Javascript 在窗口中的所有选项卡上运行Applescript
我想在google chrome的所有选项卡上运行以下AppleScriptJavascript 在窗口中的所有选项卡上运行Applescript,javascript,google-chrome,safari,applescript,Javascript,Google Chrome,Safari,Applescript,我想在google chrome的所有选项卡上运行以下AppleScript tell application "Google Chrome" to tell active tab of window 1 execute javascript "document.getElementsByClassName('bt bt3 bw4')[0].click();" end tell 我已经设法在Safari中的所有选项卡上使用 tell application "Safari"
tell application "Google Chrome" to tell active tab of window 1
execute javascript "document.getElementsByClassName('bt bt3 bw4')[0].click();"
end tell
我已经设法在Safari中的所有选项卡上使用
tell application "Safari"
repeat with t in tabs of windows
do JavaScript "document.getElementsByClassName('bt bt3 bw4')[0].click();" in t
end repeat
end tell
但无法在Chrome中复制此功能
有人有什么建议或知道这是否可行吗
谢谢因为你没有提供一个URL来测试
getElementsByClassName('bt bt3 bw4')
,我已经打开了几个谷歌Chrome窗口,每个窗口都有几个带有此问题URL的选项卡,并锁定了提问按钮,其类名为ws-nowrap s-btn s-btn\u primary
下面的示例AppleScript代码适用于我,它在每个Google Chrome窗口的每个选项卡上单击每个提问按钮:
提示:鼠标悬停并水平滚动以查看完整代码
用bt bt3 bw4
替换上面示例中的类名称ws nowrap s-btn s-btn_uuprimary
,如果在Safari版本的代码中工作,则在该谷歌Chrome版本的代码中应该适用
注意事项: •如果有多个对象具有相同的类名
'bt bt bw4
,则getElementsByClassName()
HTML DOM方法需要具有适当的索引值,如果它不是[0]
。如果不是您提供的常量值,则这可能需要额外的编码以编程方式确定正确的值
•示例AppleScript代码就是这样,不包含任何适当的错误处理。用户有责任根据需要添加任何适当的错误处理。请查看中的语句和语句。另见
tell application "Google Chrome"
repeat with t in tabs of windows
tell t to execute javascript "document.getElementsByClassName('ws-nowrap s-btn s-btn__primary')[0].click();"
end repeat
end tell