我使用VBA通过这个网站访问IE,但是我无法解决这个问题。当我开始导航到另一个窗口时,网页会跟踪是否有多个打开的窗口会话并将我注销。有没有办法继续会话并导航回上一页而不断开连接?
作为旁注,该网页不是公共领域。
这里有我无法工作的东西:
Dim IE As Object
Set IE = New InternetExplorerMedium
IE.Visible = True
'code to Login to webpage went here
Set doc = IE.document
doc.getElementById("txtFileNumber").Value = "12345678"
doc.getElementById("cmdSearch").Click
Do While .Busy Or .READYSTATE <> 4
DoEvents
Loop
Dim requested as Object
Dim trans As String
Set requested = doc.getElementById("TransitLink")
If requested.isDisabled = False Then
trans = requested.href
End If
IE.navigate trans ' <----msgbox comes up "Multiple sessions not allowed"
这是HTML代码的一部分,如果这有帮助的话。
<a id="TransitLink" title="In Transit" class="button" onClick="inqPopups[7] = window.open(this.href, 'popup7', 'WIDTH=350,HEIGHT=250,scrollbars,resizable,status,toolbar=yes'); (document.getElementById('txtFileNumber')).focus(); (document.getElementById('txtFileNumber')).select(); inqPopups[7].focus(); return false;" href="TransactionInTransit.aspx?... style="color:Blue;">In Transit</a>
var inqPopups = new Array();
function closeSubWindow() {
for (var i = 0; i < inqPopups.length; i++) {
if (inqPopups[i] && !inqPopups[i].closed) {
inqPopups[i].close();
}
}
}
答案 0 :(得分:0)
尝试使用With IE
并执行所有代码和End With
Dim IE As Object
Set IE = New InternetExplorerMedium
Wtih IE
.Visible = True
'code to Login to webpage went here
Set doc = IE.document
doc.getElementById("txtFileNumber").Value = "12345678"
doc.getElementById("cmdSearch").Click
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Dim requested As Object
Dim trans As String
Set requested = doc.getElementById("TransitLink")
If requested.isDisabled = False Then
trans = requested.href
End If
.navigate trans
' Rest of code
.Quit ' close ie window
End With 'once done with IE window
由于你有Set IE = New
,它每次都会创建一个新的IE实例。因此,要将其全部保存在一个窗口中,您必须使用With IE
End With
方法。