2015-11-09 62 views
0

我想使用谷歌浏览器自动登录网站(https://account.nicovideo.jp/login)。如何使用Applescript通过Chrome自动登录到网站?

我知道如何在Safari上使用Applescript,但我不知道如何为Chrome编写脚本。

这是我的Applescript for Safari的自动登录。我怎么能用Chrome做同样的事情?


tell application "Safari" 
    activate 
    if URL of document 1 starts with "https://account.nicovideo.jp/login" or URL of document 1 starts with "https://secure.nicoga.jp/" then 
     do JavaScript "document.forms[0].mail_tel.value='[email protected]'" in document 1 
     do JavaScript "document.forms[0].password.value='password in here'" in document 1 
     do JavaScript "document.forms[0].submit()" in document 1 
    end if 
end tell 

回答

0

你执行JavaScript,并且对象被附接到窗口的选项卡。所以:

tell application "Google Chrome" 
    activate 
    tell window 1 
     tell active tab 
      if (its URL) starts with "https://account.nicovideo.jp/login" or (its URL) starts with "https://secure.nicoga.jp/" then 
       execute javascript "document.forms[0].mail_tel.value='[email protected]'" 
       execute javascript "document.forms[0].password.value='password in here'" 
       execute javascript "document.forms[0].submit()" 
      end if 
     end tell 
    end tell 
end tell