2017-08-02 63 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