2017-12-05 12 views
0

ID가없는 입력 필드에 텍스트를 입력하려고합니다. 요소를 검사하면 다음과 같이 표시됩니다.VBA - IE 자동화 - .getelements

<input title="Affected Customer(s)" class="custom-input ng-pristine ng-invalid ng-invalid-required ng-touched" role="combobox" aria-expanded="false" aria-required="true" aria-owns="typeahead-78-1606" aria-autocomplete="list" required="" type="text" placeholder="Enter customer name, email, login ID or corporate ID" entity="incident" field-name="customer.loginId" potentially-required-field="" auto-focus="" typeahead="user as user.firstName + ' ' + user.lastName for user in getList('person', $viewValue)" typeahead-loading="person.isLoading" typeahead-wait-ms="500" typeahead-on-select="onCustomerSelect($model)" typeahead-template-url="views/create/custom-add-user-dropdown.html" typeahead-min-length="3" prevent-click-event="" ng-model="person.ngModel"> 

이 입력란은 어떻게 참조합니까? 나는 여러 가지 방법을 시도했지만 모두 실패합니다. 나는 나의 이해가 부족하다고 생각하며, 희망을 갖고 약간의 도움이 나를 올바른 길로 인도 할 것입니다. 이 입력 필드를 찾으려고 내가 지금 가지고있는 코드는 다음과 같습니다

Sub Automate_IE_Load_Page() 
'This will load a webpage in IE 
Dim i As Long 
Dim URL As String 
Dim IE As Object 
Dim objElement As Object 
Dim objCollection As Object 
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element 

'Create InternetExplorer Object 
Set IE = CreateObject("InternetExplorer.Application") 

'Set IE.Visible = True to make IE visible, or False for IE to run in the background 
IE.Visible = True 

'Define URL 
URL = "https://ewpg-app-1041.hydro.mb.ca/ux/smart-it/#/create/incident" 

'Navigate to URL 
IE.navigate URL 



' Wait while IE loading... 
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop) 
Do While IE.readyState = 4: DoEvents: Loop 'Do While 
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until 


objIE.Document.getElementsByName("customer.loginId")(0).Value = "test" 

'click create new 
'for each <a> element in the collection of objects with class of 'result__a'... 
For Each aEle In objIE.Document.getElementsByName("Affected Customer(s)") 

    '...get the href link and print it to the sheet in col C, row y 
    result = aEle 

'repeat times the # of ele's we have in the collection 
Next 


'Unload IE 
Set IE = Nothing 
Set objElement = Nothing 
Set objCollection = Nothing 

End Sub 

라인 "objIE.Document.getElementsByName ("customer.loginId은 ") (0) .Value는 ="테스트 ""나에게 오류를 제공 런타임 오류 424 - 예상 된 개체입니다.

제공 할 수있는 도움을 주셔서 감사합니다. 이것은 매우 쉽지만 분명히 기본적인 것을 분명히 이해하지 못하고 있습니다. 위의 코드는 다양한 사이트에서 가져 와서 제대로 작동하는 것 같습니다. 나는 다른 논리를 사용하여 테스트하기 위해 노력했다. 대신 코드 아래

답변

0

시도 :

getElementsByClassName("custom-input ng-pristine ng-invalid ng-invalid-required ng-touched") 
+0

가 아 ... 난을 참조하십시오. 나는 오늘 일할 때 그것을 시도 할 것입니다. 고맙습니다. –

+0

나는 당신의 코드를 시험해 보았다. 그것은 여전히 ​​나에게 런타임 오류 424 - 객체를 예상했다. –

+0

작동하도록했습니다 !!!!!!! objIE.document.getElementsByClassName ("사용자 정의 입력 NG-자연 그대로의 NG-무효 NG-무효 필수 NG-감동") (0) .Value = "테스트" 확실이 롤 이전에 작동하지 않은 이유. –