你得到這個錯誤,因爲你沒有給它足夠的時間來驗證FROM
和TO
下拉框的名字(是 - 不是文本框)
試試這個代碼(屢試不爽)。另外我使用IE的Late Binding。根據您的代碼進行更改。
Sleep 5000
在下拉列表中給文本足夠的時間用下拉列表驗證自己。
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Click_Btn()
Dim objForms As Object
Dim vTxtInput As Variant
Dim objIE As Object
Set objIE = CreateObject("InternetExplorer.Application")
'Make sure an IE object was hooked
If TypeName(objIE) = "Nothing" Then
MsgBox "Could not hook Internet Explorer object", _
vbCritical, "GetFields() Error"
'GoTo Clean_Up
End If
objIE.Navigate "http://fly3.emirates.com/CAB/IBE/SearchAvailability.aspx"
objIE.Visible = True
Sleep 5000
Set objForms = objIE.document.all
'~~> Choose one way Flights
objIE.document.getElementById("ctl00_c_CtWNW_onewaySearch").Click
'~~> From
objIE.document.getElementById("ctl00_c_CtWNW_ddlFrom-suggest").Focus
objIE.document.getElementById("ctl00_c_CtWNW_ddlFrom-suggest").Value _
= "Mumbai (BOM)"
Sleep 5000
'~~> Departure Date
objIE.document.getElementById("ctl00_c_CtWNW_txtDepartDate").Focus
objIE.document.getElementById("ctl00_c_CtWNW_txtDepartDate").Value _
= "28 Sep 12"
Sleep 5000
'~~> To
objIE.document.getElementById("ctl00_c_CtWNW_ddlTo-suggest").Focus
objIE.document.getElementById("ctl00_c_CtWNW_ddlTo-suggest").Value _
= "Sydney (SYD)"
Sleep 5000
objIE.document.getElementById("ctl00_c_FS_FF").Focus
objIE.document.getElementById("ctl00_c_FS_FF").Click
End Sub
編輯
這裏是Way 2
,這是快於Way 1 (Above)
通過15 Seconds
,因爲我們沒有使用Sleep 5000
用於驗證。這並不要求你驗證下拉菜單。它所做的是繞過checkValidation();
javascript,它在提交按鈕的ONCLICK事件中執行。
WAY 2
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Click_Btn()
Dim objForms As Object
Dim vTxtInput As Variant
Dim objIE As Object
Set objIE = CreateObject("InternetExplorer.Application")
'Make sure an IE object was hooked
If TypeName(objIE) = "Nothing" Then
MsgBox "Could not hook Internet Explorer object", _
vbCritical, "GetFields() Error"
'GoTo Clean_Up
End If
objIE.Navigate "http://fly3.emirates.com/CAB/IBE/SearchAvailability.aspx"
objIE.Visible = True
Sleep 5000
Set objForms = objIE.document.all
'Choose one way Flights
objIE.document.getElementById("ctl00_c_CtWNW_onewaySearch").Click
' From
objIE.document.getElementById("ctl00_c_CtWNW_ddlFrom-suggest").Focus
objIE.document.getElementById("ctl00_c_CtWNW_ddlFrom-suggest").Value _
= "Mumbai (BOM)"
' Departure Date
objIE.document.getElementById("ctl00_c_CtWNW_txtDepartDate").Focus
objIE.document.getElementById("ctl00_c_CtWNW_txtDepartDate").Value _
= "28 Sep 12"
' To
objIE.document.getElementById("ctl00_c_CtWNW_ddlTo-suggest").Focus
objIE.document.getElementById("ctl00_c_CtWNW_ddlTo-suggest").Value _
= "Sydney (SYD)"
objIE.document.getElementById("ctl00_c_FS_FF").Focus
objIE.document.getElementById("ctl00_c_FS_FF").onclick = _
Replace(objIE.document.getElementById("ctl00_c_FS_FF").onclick, _
"checkValidation();", "true;")
objIE.document.getElementById("ctl00_c_FS_FF").Click
End Sub
+ 1有趣的問題:) –