私は、IEアプリケーションを介してGoogleとのやりとりをシミュレートしようとしています。私は必要なクラスを取得するためにDOMを通過しますが、.Click
クラッシュを引き起こすことはありませんが、それは何もしないアクション(ページが移動しません) - コードと下のHTMLのスクリーンショット:。何もしないアクション - IEシミュレーション
Option Explicit
Private Sub Test_Automation()
Dim ie, doc, eInput, eButton, eButtons As Object
Dim sURL, sTest As String
Set ie = CreateObject("internetexplorer.application")
sURL = "https://www.google.co.uk/?gfe_rd=cr&ei=IpDvWK72LsjCaJCbjKAL&gws_rd=ssl"
sTest = "Test"
With ie
.Visible = True
.Navigate sURL
End With
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Set doc = ie.document
Set eInput = doc.getElementByid("lst-ib")
Set eButtons = doc.getElementsByTagName("input")
eInput.Value = sTest
For Each eButton In eButtons
If (eButton.getattribute("name") = "btnK") Then
eButton.Click
Exit For
End If
Next
End Sub
私がやっている上の任意のアドバイス間違ったことは素晴らしいだろう!
おそらく 'eInputs.Value'は' Inputs.Value'でしょうか? – Amorpheuses
あなたのコードにはいくつかの欠陥があります。どこでも 'eInputs'を定義していないので、エラーを投げる' eInputs.Value = sTest'は特にありません。これを読んでください:http://stackoverflow.com/help/mcveそしてあなたの質問を編集します。 –
デバッグするときは、モジュールの上部で 'Option Explicit'を使うのが本当に役に立ちます。 – Amorpheuses