2017-05-03 15 views
1

ウェブサイト「https://testmysite.thinkwithgoogle.com」に移動するコードを作成しようとしています。検索フィールドに文字列を入力し、ボタンを送信して結果を取得します(最終的にスクラップしてファイルを上書きする)。VBAセレニウムボタン送信問題

ただし、ボタンを送信できません。私が試した反復は、テキストを入力した後に表示される削除テキストXを送信します。以下は私のコードです:

Sub GetScores() 
Dim bot As New WebDriver 

' URL to get data from 
bot.Start "Chrome", "https://testmysite.thinkwithgoogle.com" 
bot.Get "/" 

' Eventually loop through websites, for now just use example 
Dim str As String 
str = "www.google.com" 

'Paste str into webpage 

bot.FindElementByName("pagespeed-input").SendKeys (str) 

bot.FindElementByClass("pagespeed__submit").Submit 

そしてここでは、ウェブサイトからhtmlコードです:

<div class="pagespeed " data-component="PageSpeed" > 
    <form class="pagespeed__form" action=""> 
     <input type="hidden" name="pagespeed-locale" id="" value="en_us"> 
     <input type="url" name="pagespeed-input" class="pagespeed__input" placeholder="Enter your website URL" tabindex="-1" autofocus > 
     <button type="submit" class="pagespeed__submit pagespeed__submit--disabled" data-gtm-id="smbhub-url-entry" disabled>Test now</button> 
    </form> 
    <div class='pagespeed__error'></div> 
    </div> 
+0

'Submit'の代わりに' Click'を試しましたか? – Tehscript

+0

私はして、私はエラーメッセージが表示されます。上記のバージョンはボタンクリック/サブミットを実際に達成した唯一のものです。それはちょうど間違ったものです –

答えて

0

bot.FindElementByXPath("//button[@type='submit']").Click

代わりの

bot.FindElementByClass("pagespeed__submit").Submit

を使用してみてください
+0

それは働いた!本当にありがとう! –

+0

@LindseyD素晴らしいあなたはこの回答を受け入れることができますか? –

+0

完了しました、もう一度! –

関連する問題