2015-11-09 95 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