2017-01-16 4 views
0

그러나 내가 알고있는 동일한 줄에있는 많은 게시물은 실제로이 작업을 수행하는 데 어려움을 겪고 있습니다.VBA IE 양식 자동화

웹 사이트에 로그인하고 양식이있는 새 탭을 여는 코드를 만들었지 만 다른 게시물의 다양한 예를 시도해도 양식에 데이터를 입력 할 수 없습니다.

내가 지금 가지고있는 코드는 : 나는 실제 URL/암호 등을 제공 드릴 수 없습니다

''======================================================= 
'' Program: MyQuote 
'' Desc:  Writes Data into online web form from data in workbook 
'' Called by: Batch File (MyQuote.bat) 
'' Call:  MyQuote 
'' Info: 
    ''This macro has been built improve the time it takes to gain a quotation from the MyQuote website. 
    ''Once an agent has completed a quote on the inhouse system, they will run batch file (MyQuote.bat) which FTP's out the quote data, imports it into this 
    ''workbook, and uses that data to fill the quote forms on the MyQuote website. 
    ''The macro creates a new instance of Internet Explorer, navigates to the site, enters the username and password to login, and navigates through 
    ''each question entering the variable extracted from our quote system. 
'' Changes---------------------------------------------- 
'' Date   Programmer  Change 
'' 13/01/2017 Craig    Written 
''======================================================= 
Sub MyQuote() 

'Declaring the necessary variables. 
    Dim IE    As Object 


Dim Bton1 As HTMLGenericElement 


'Set browser 
     Set IE = CreateObject("InternetExplorer.Application") 

'Log Off if already logged in 
     IE.navigate "http://www.example.com/logout" 

'Wait until IE has loaded 
     Do Until IE.readyState = 4 
      DoEvents 
     Loop 


'Navigate to My Quote Website 
     IE.navigate "http://www.example.com/" 

'Wait until IE has loaded 
     Do Until IE.readyState = 4 
      DoEvents 
     Loop 


'Enter values and login to My Quote Website 
     IE.document.all.Item("UserName").Value = "[email protected]" 
     IE.document.all.Item("Password").Value = "abc" 


'Find and press the submit button 
     Set objCollection = IE.document.getElementsByTagName("button") 


     If objCollection(i).Type = "submit" Then 
      Set objElement = objCollection(i) 
     End If 


     objElement.Click 


'Wait while IE re-loads... 
     While IE.Busy 
      DoEvents 
     Wend 

'Find and press the New Quote button 
     Set objCollection = IE.document.getElementsByTagName("button") 

     If objCollection(i).className = "btn btn-success btn-xs" Then 
      Set objElement = objCollection(i) 
     End If 


     objElement.Click 


'Wait while IE re-loads... 
     While IE.Busy 
      DoEvents 
     Wend 


'Find and press the Agree button on Credit Check pop up overlay 
     For Each l In IE.document.getElementsByTagName("button") 
      If l.className = "btn btn-success" Then l.Click 
      Next 

'Wait while IE re-loads... 
     While IE.Busy 
      DoEvents 
     Wend 

'Enter Registration 
     '=====below is what is not working====== 
     'IE is now in a new tab with different URL if that helps 
     IE.document.all.Item("Registration").Value = "AB12CDE" 

     End With 




End Sub 

.. 사이트의, 그러나 아래의 페이지 요소의 HTML의 조각이다 나는 작업 얻기 위해 노력하고 있어요 :

     <input type="text" name="Registration" id="Registration" class="form-control reg-input" data-bind="value: Registration" placeholder="REGISTRATION"> 
         <button id="btn-findVehicle" class="btn btn-primary" type="button" data-bind="click: $parent.findVehicle">Find your car </button> 

내가 개체를 선택하려고 때문이고 나는 새로운 IE 탭에서 지금 생각하면 나도 몰라,하지만 난려고 10 시간 보냈어요 행운이없는이 일.

일단이 문제가 해결되면 다른 40 개의 필드, 라디오 버튼, 메뉴 드롭 다운 메뉴 & 제출 버튼 (나에게 운이 좋음)을 매핑하여 계속 진행할 수 있습니다.

도움과 조언을드립니다.

감사

크레이그

답변

0

나는 당신의 ID가 정말 eassy 때문에 찾기 위해에서 getElementById 메소드를 사용하여 정적 찾고, 당신은 MSDN에서 방법을 확인할 수 있습니다 것이 좋습니다.

무료 서드 파티 소프트웨어 덕분에 많은 브라우저 작업을 자동화했습니다. 확인할 수 있습니다 - OPEN TWEBST. 전자 서명이 필요한 웹 페이지를 탐색 할 때만 문제가있었습니다.

희망이 있습니다.

+0

답변 주셔서 감사합니다. Alen, 저는 ID 요소에도 익숙합니다. 실제로 브라우저가 문제를 일으키는 다른 탭으로 이동했기 때문입니다. 방금 현재 탭에서 열어 본 페이지로 이동했는데 모두 작동합니다. 감사합니다. –