为什么我的getElementById()结果和"缺失值"在AppleScript的? [英] Why does my getElementById( ) result with "missing value" in Applescript?

查看:357
本文介绍了为什么我的getElementById()结果和"缺失值"在AppleScript的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是确定一个元素是否是一个页上的和该元素上执行一个动作,如果它的存在。

My goal is to determine whether or not an element is on a page and perform an action on that element, if it exists.

在此code,我只显示试图执行元件动作的第二部分。

In this code, I'm only showing the second part of trying to perform an action on an element.

我的code是:

tell application "Safari" 
    open location "http://www.apple.com" 
    tell front document 
        do JavaScript "document.getElementById(\"gn-store\").click()" 
    end tell 
end tell 

不过,我总是得到缺失值,从这个code和我试过类似的东西(包括调用JS中的函数,结果从的getElementById()返回一个值。

However, I always get a result of "missing value", from this code and similar things I've tried (including calling a function in Js, to return a value from getElementById( ).

我不明白我在做什么错。我一直盯着它几个小时。 (并记录在案,我是一个AppleScript小白)。

I don't understand what I'm doing wrong. I've been at it for hours. (and for the record, I am an applescript noob).

推荐答案

我发现铬通过AppleScript的...

I find Chrome reacts better to Javascript via AppleScript...

tell application "Google Chrome"
    if not (exists window 1) then reopen
    activate
    tell window 1 to tell active tab
        set its URL to "http://www.apple.com/"
        delay 3
        execute javascript "document.getElementById('gn-store').childNodes[0].click()"
    end tell
end tell

这篇关于为什么我的getElementById()结果和"缺失值"在AppleScript的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆