在IE8中打破了VBscript(屏幕抓取)

时间:2011-01-21 22:28:22

标签: vbscript

写了一个vbscript来获取fedex报价。在IE6中工作得很好但是在IE8(任何模式)打破了 错误:需要对象:'element'代码:800A01A8

我在这里难倒的是代码:

dim ie1

dim wsh : Set wsh = CreateObject("WScript.Shell")

Dim ArgObj, var1, var2, var3, var4: Set ArgObj = WScript.Arguments  
var1 = 2.5 'ArgObj(0) 'First parameter
var2 = 2.5 'ArgObj(1) 'Second parameter
var3 = 2.5 'ArgObj(2) 'Third parameter
var4 = 2.5 'ArgObj(3) 'Fourth parameter


dim zip
zip=InputBox("Please enter destination zip code - You must have Internet access for this to work", " Destination Zip Code", 12345) 
Const URL = "https://www.fedex.com/ratefinder/home?cc=US&language=en&locId="
set ie1=WScript.CreateObject("InternetExplorer.Application")
with ie1
  .Visible =1

'dim wsh : Set wsh= CreateObject( "WScript.Shell" )
'dim iefocus
'Do Until iefocus
'iefocus=wsh.AppActivate("Microsoft Internet Explorer")

'Loop

  .Navigate URL
  Do Until .ReadyState = 4
    WScript.Sleep 50    ' wait for page to load
  Loop


On Error resume next
  With .document.forms("logonForm")
 .username.value = ""      ' enter company into a textbox
 .password.value = ""      ' enter name into a textbox
 .submit

WScript.Sleep 100    ' wait for page to load
Do Until ie1.busy=0
    WScript.Sleep 50    ' wait for page to load
  Loop

End With

On Error Goto 0
With ie1.document.forms("standAloneActionForm")


 .origZip.value = "84016"
 .destZip.value=zip
 .receivedAtCode.value=1
 .totalPackageWeight.value=var1


    For Each element in .elements
      If element.type = "button" and element.value="Get detailed quote" Then
element.click
      End If
    Next

WScript.Sleep 500    ' wait for page to load
Do Until ie1.busy=false
    WScript.Sleep 50    ' wait for page to load
  Loop


With ie1.document.forms("standAloneActionForm")
    For Each element in .elements

    If element.type = "text" Then

'.if element.value="Select" then element.value.selectedindex=1
if element.value="L" then element.value=var2
if element.value="W" then element.value=var3
if element.value="H" then element.value=var4

    End If
    Next



With ie1.document.forms("PackageList")

' .packageType.value=1
'    For Each element in .elements

    If element.type = "Select" Then
.packageType.value=1
'if element.value="Select" then element.value=1

    End If
   ' Next



'    For Each element in .elements
      If element.type = "button" and element.value="Continue" Then
element.click
      End If
'    Next



end with
end with
end with
end with

它在“PackageList”之后中断,这是一个下拉框。

任何想法都会有所帮助。

1 个答案:

答案 0 :(得分:0)

测试想法以缩小问题范围:您可以在免费iMacros Internet Explorer addon中记录相同的序列。如果它在那里工作,那么你知道这是你的代码的问题。如果iMacros宏不起作用,那么这个特定网站的IE问题就不存在了。