2017-09-14 13 views
0

新しいSafariウィンドウにURLのリストを開くスクリプトがありますが、JavaScriptコマンドは機能していないようです。私はconsole.logにこだわっていますが、これはインスペクタに表示されないテストとしても表示されません。 JavaScriptの前の遅延を17まで変更しようとしました。AppleScriptで動作するJavaScriptコマンドの取得

「subscribe-button」は、ログインしているときに「編集」ボタンをクリックすると表示されます。

on run {input, parameters} 
    read (item 1 of input) 
    set ps to paragraphs of the result 
    set tot to count ps 
    tell application "Safari" 
     reopen 
     activate 
    end tell 
    repeat with i from 1 to tot 
     set p to item i of ps 
     if p is not "" then 
      try 
       tell application "Safari" 
        tell front window 
         set r to make new tab with properties {URL:p} 
         set current tab to r 
         delay 1 
         do JavaScript "console.log('test this log')" 
         do JavaScript "document.getElementsById('subscribe-button').click()" 
         if i = tot then exit repeat 
         repeat 
          delay 1 
          get URL of r 
         end repeat 
        end tell 
       end tell 
      end try 
     end if 
    end repeat 
end run 
+0

デバッグコードのヘルプが必要な場合は、[最小限の完全かつ検証可能な例](https://stackoverflow.com/help/mcve)を提供する必要があります。 – user3439894

+0

それは本当に役に立たないコメントですが、とにかく自分の質問に答えました。 – VagueExplanation

+0

SafariでJavaScriptを使用してボタンをクリックしても、do JavaScriptを使用して問題はありません。document.getElementsById( 'elementID')。私はそれを適用したWebページのdocument 1内の()をクリックします。 ** MCVE **についての私のコメントに関しては、** SO ** **の無言のルールですが、いつかリマインダが必要です! **あなたのコードをテストしたり、ターゲットページのコードを見たりするためのURLを提供していないので、私と他の人のために何度も何度も働いていたものを提供することができます** – user3439894

答えて

0

do JavsScriptを「現在のタブ」に設定して遅延を増やすと、console.logが機能することがわかりました。

on run {input, parameters} 
    read (item 1 of input) 
    set ps to paragraphs of the result 
    set tot to count ps 
    tell application "Safari" 
     reopen 
     activate 
    end tell 
    repeat with i from 1 to tot 
     set p to item i of ps 
     if p is not "" then 
      try 
       tell application "Safari" 
        tell front window 
         set r to make new tab with properties {URL:p} 
         set current tab to r 
         delay 10 
         do JavaScript "console.log('test this log')" in current tab 
         if i = tot then exit repeat 
         repeat 
          delay 10 
          get URL of r 
         end repeat 
        end tell 
       end tell 
      end try 
     end if 
    end repeat 
end run 
+0

あなたは ' JavaScriptを使用する "document.getElementsById( 'subscribe-button')。あなたの答えでclick()" '?ボタンをクリックしましたか? – user3439894

+0

いいえ、主に私の問題は、JavaScriptをまったく実行させることでした。それは私に、そのアイデアの要素が存在しないというエラーを与えました。私は、ページが完全に読み込まれていないことが原因と思われるかもしれません。これは遅延やページが読み込まれたかどうかを検出する別のスクリプトで修正される可能性があります。関連するYouTube動画IDで汎用の動画編集URLを使用するだけで済みますので、もうボタンをクリックしません。 – VagueExplanation