Trying to fill web form with VBA, can´t address el

2019-08-16 08:28发布

问题:

I am trying to fill out a web form in IE with data from a workbook but I am having trouble addressing the text box since it seems to lack a name.

The site is behind a login so no link, sorry. But the element presents itself as

<input type="text" placeholder="  Søg på brugernavn, referencenummer, eller e-mail" ng-model="filterSearch.search" ng-change="filterOnSearch()" ng-model-options="{ debounce: 500 }" class="ng-pristine ng-valid ng-empty ng-touched">

when inspecting it in chrome.

I have tried

ie.document.getelementsbyclassname("ng-pristine ng-valid ng-empty ng-touched").Value = "11"

but VBA throws me a run-time error '438': Object doesn't support this property or method.

Any suggestions?

回答1:

It may sound confusing but anytime you are trying to pull an element by classname you need to use the

.item(0)

after that you would use something similar to

ie.document.getelementsbyclassname("ng-pristine ng-valid ng-empty ng-touched").item(0).Value = "11"

This is assuming that you are trying to fill out an input box that has the class above and that the element is the only 1 in its class or the first one.

In the event that it does not work it may not be the first element in that class and then you may need to do item(1) or item(2) etc.