如何让 AppleScript 单击网页上的按钮或链接?
我正在尝试获取 Apple 脚本来单击网页中的某个项目。下面的这个脚本有点工作,我可以让它点击不同的 safari 选项卡或下拉菜单,但我无法让它点击网页中的项目。
在这个例子中,我试图让脚本点击谷歌的“我感觉幸运”按钮。除了由于某种原因点击之外,它都有效:
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
open location "http://google.com"
click at {655, 382} -- {from left, from top}
end tell
end tell
按钮的位置可能会根据屏幕尺寸而有所不同,但任何人知道为什么这不起作用吗?
I am trying to get an Apple Script to click on an item within webpage. This script below works somewhat, I can get it to click different safari tabs or drop down menus, but I cannot get it to click an item within webpage.
In this example, I am trying to get the script to click the "Im feeling Lucky" button from google.. it all works except the click for some reason:
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
open location "http://google.com"
click at {655, 382} -- {from left, from top}
end tell
end tell
The location of the button will likely be different depending on screen size, but anyone have any idea why this is not working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜这是因为页面尚未加载。尝试在调用
open location
后添加延迟。使用Javascript来点击按钮会更灵活,你可以这样做:I'd guess it's because the page hasn't loaded yet. Try adding a delay after you call
open location
. Using Javascript to click the button would be more flexible, you can do something like this: