2017-08-02 32 views
0

我正嘗試使用VBA登錄此網頁,https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp 。調試表明,當用戶名行處於活動狀態(顯然它不能填充用戶名數據)時,VBA會引發所需的錯誤424對象。無法使用excel登錄網頁,需要使用錯誤424對象

下面的代碼:

Sub Test() 

    Set ie = CreateObject("InternetExplorer.application") 
    ie.Visible = True 
    ie.Navigate ("https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp") 
    With ie.document 
     .getElementById("txtUserId").Value = "ABCDE" 
     .getElementById("txtPassword").Value = "ABCDE" 
     .getElementById("submit").Click 
    End With 

End Sub 

誰能幫我同時登錄到指定的網頁調試問題?

+0

該網頁有框架,你所提供的網址是頂部幀。登錄部分的真實URL是:https://www.fois.indianrail.gov.in/ecustomer/JSP/LoginNew.jsp –

+0

假設Logan是正確的,您將希望導航到框架的文檔,然後通過ID獲取元素。您應該能夠通過名稱,班級或ID獲取框架。 –

+0

嘗試在VBS中使用.getElementsByName(「txtUserId」)。 –

回答

1

在下面的例子看看:

Option Explicit 

Sub Test() 

    Dim oIE As Object 

    Set oIE = CreateObject("InternetExplorer.application") 
    With oIE 
     .Visible = True 
     .Navigate ("https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp") 
     Do While .ReadyState < 4 Or .Busy 
      DoEvents 
     Loop 
     With .Document 
      Do While .ReadyState <> "complete" 
       DoEvents 
      Loop 
      With .parentWindow.frames("frmCUMain").document 
       .getElementsByName("txtUserId")(0).Value = "ABCDE" 
       .getElementsByName("txtPassword")(0).Value = "ABCDE" 
       .getElementsByName("cmdLogin")(0).Click 
      End With 
     End With 
    End With 

End Sub