1

The HTML code is as follows: Password node:

<input name="customerPassword" type="password" class="customer-password form-control ng-dirty ng-valid-required filled ng-valid ng-valid-minlength" ng-class="{
  'input-error': submitted &amp;&amp; securityForm.customerPassword.$invalid,
  'filled': securityForm.customerPassword.$viewValue.length>0}" ng-minlength="7" maxlength="20" ng-model="customer.password" ng-keydown="checkEnterKey(event)" required="" autocomplete="new-password" aria-autocomplete="list">

Secuirty nodes

<li class="sec-number ng-scope control-disabled" ng-repeat="n in securityCode track by $index" ng-class="{'control-disabled': securityForm.customerPassword.$invalid}">
    <!-- ngIf: n -->
    <input name="secNumber1" type="password" maxlength="1" class="input-code form-control ng-scope ng-pristine ng-valid-pattern ng-invalid ng-invalid-required" ng-class="{'filled': customer.code[$index] !== undefined}" ng-model="customer.code[$index]" ng-if="n" ng-disabled="securityForm.customerPassword.$invalid" ng-pattern="/\d{1}$/" met-only-number="" required="" focus-next="" disabled="disabled">
    <!-- end ngIf: n -->

    <!-- ngIf: n --><b class="into-input position ng-binding ng-scope" ng-if="n">
                    1
                    <span class="ordinal ng-binding">st</span>
                </b>
    <!-- end ngIf: n -->

    <!-- ngIf: !n -->
</li>

"secNumber" can be anything between 1 to 8. Part of VBA code is as follows:

Set oPassword = .document.getElementsByName("customerPassword")(0)
oPassword.Focus
oPassword.Value = Password
oPassword.Focus

Dim strsecnum As String

For i = 1 To 8

    strsecnum = "secNumber" & i

    For Each ele In .document.getElementsByName(strsecnum)

        Set ele = .document.getElementsByTagName(strsecnum)(0)
        ele.Value = i

    Next

Next i

I am getting error 91, "Object Variable or With Block Variable not set" on ele.value = i. ele is defined as Object, so I am not sure what is the problem.

6
  • 1
    Have you checked .document.getElementsByName("secNumber1").length? Using lower case s Commented Apr 26, 2020 at 22:27
  • Thank you very much @QHarr, it works with lower case. I am however getting error 91 "Object variable or With block variable not set". on oChr.Value = 1 part. the line above clearly sets teh value so i am not sure what is the problem here? Commented Apr 29, 2020 at 20:28
  • How is oChr declared?And does error go away if you execute code line by line with F8? Your loop is also redundant as you only ever work with the first element, so you could just replace all that code with .document.querySelector("[name='secNumber1']").value = 1 Attributes in html are case sensitive for parsing hence the need for s. Commented Apr 29, 2020 at 21:40
  • @QHarr, thank you. oChr and ele are declared as Object yes. I put a loop there as the elements can be any 3 numbers of 8 and the loop is checking for all of them and filling the right one. It looks something like this: ....Dim strsecnum As String For i = 1 To 8 strsecnum = "secNumber" & i For Each ele In .document.getElementsByName(strsecnum) Set ele = .document.getElementsByTagName(strsecnum)(0) ele.Value = i Next Next i .... but i am still getting the same error, with F8 too. Commented Apr 30, 2020 at 8:26
  • 1
    Can you add that code, formatted to question please using edit Commented Apr 30, 2020 at 11:31

1 Answer 1

1

Your error is likely occurring because you are assuming all 8 possibilities exist in the code above.

You can alter the loop and use a css attribute = value selector with starts with operator to target only values which exist. As the values are between 1-8, and we can see the expected values are indeed single digit from html (ng-pattern="/\d{1}$/"), we can assign the value to the right based on the left hand side name attribute's value:

Dim i As Long

For i = 0 To ie.document.querySelectorAll("[name^='secNumber']").Length - 1
    ie.document.querySelectorAll("[name^='secNumber']").item(i).value  = Right$(ie.document.querySelectorAll("[name^='secNumber']").item(i).getAttribute("name") , 1)
Next 

If you work with variables instead you will gain a small efficiency:

Dim i As Long, secNumberNodeList As Object, secNumberNode as Object

Set secNumberNodeList = ie.document.querySelectorAll("[name^='secNumber']")

For i = 0 To secNumberNodeList.Length - 1
    Set secNumberNode = secNumberNodeList.item(i)
    secNumberNode.value = Right$(secNumberNode.name , 1)
Next 

Note that attribute values are case sensitive, hence you need the s in secNumber. You can ignore case (for characters within the ASCII range) with i modifier.

Sign up to request clarification or add additional context in comments.

8 Comments

thank you very much, learned a lot actually. Unfortunately both solutions do not seem to work. While both suggestion will the text boxes with correct data, it seems that something the text boxes become unresponsive and the next step is still asking to fill in the data. Could there be something in the suggested code disables those text boxes?
I can't say. Does it make a difference if you put an Application.Wait Now + timeserial(0,0,1) inside the loop? Also, can you perform the required actions manually?
Yes, it does allow to do it manually. Waiting did not work unfortunately. Does it matter that it opens up internet explorer, instead of Chrome or Edge?
Try secNumberNode.focus before assigning the value
I think I know what it is. one of the previous steps in the code assigns the password to a password field. Set oPassword = .document.getElementsByName("customerPassword")(0) oPassword.Value = Password oPassword.Focus. This works without any errors and the loop suggested is in the next step. However secNumber tex boxes get only activated when I click inside the password text box manually when gong through the code with F8. It seems oPassword.Focus does not do the trick.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.