为什么在打开浏览器的相同代码时,Applescript中的“javascript”调用不会执行? [英] why doesn't 'do javascript' call in Applescript execute when the same code typed into browser does?
问题描述
转到搜索结果页面,我试图找出为什么我的Applescript不会执行任何操作,例如: http://www.google.com/search?q=test 。为了正确的行为,请在位置栏中输入,然后按Enter键:
javascript:document.getElementsByClassName('vspib' 0]。点击();
您会看到它为第一个搜索结果选择放大镜。
这是我想通过javascript发生的事情。所以我输入以下内容:
告诉应用程序Safari
激活
做JavaScript文档。 getElementsByClassName方法( 'vspib')[0]。点击();在文件1
结束告诉
但是,它什么都不做。任何想法?
问题是做JavaScript
必须正确在Safari窗口中寻址一个选项卡。
如果搜索结果页面是最前面的Safari窗口中的当前选项卡,以下脚本适用于我:
告诉应用程序Safari
激活
将theScript设置为document.getElementsByClassName('vspib')[0] .click ();
在第一个窗口的当前选项卡中执行JavaScript theScript
end tell
I'm trying to figure out why my Applescript does nothing when the same javascript code typed into a Safari location bar works.
Go to a search results page, such as: http://www.google.com/search?q=test . For the correct behavior, type this into the location bar and hit enter:
javascript: document.getElementsByClassName('vspib')[0].click();
You'll see that it selects the magnifier for the first search result.
This is what I want to make happen via javascript. So I typed up the following:
tell application "Safari"
activate
do JavaScript "document.getElementsByClassName('vspib')[0].click();" in document 1
end tell
However, it does nothing. Any ideas?
The problem is that do JavaScript
has to correctly address a tab in a Safari window.
The following script works for me, if the search results page is the current tab in the frontmost Safari window:
tell application "Safari"
activate
set theScript to "document.getElementsByClassName('vspib')[0].click();"
do JavaScript theScript in current tab of first window
end tell
这篇关于为什么在打开浏览器的相同代码时,Applescript中的“javascript”调用不会执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!