0

Hi i need to enter a car reg into the below input box:

<input type="text" class="form-control text-uppercase car-registration__input ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" 
data-ng-model-options="{updateOn: 'blur'}" 
data-ng-keyup="inputChange=true; regnumberNotFound=false; carLookupButtonSubmitted=false" data-motor-regnumber="" 
data-msm-answer-store-key="" data-ng-required="true" 
data-msm-answer-store-action="{'regnumberUpdate': {'targets': [{}]}}" 
data-msm-error-tracking-view-change="" id="regnumber" name="regnumber" 
data-ng-model="regnumber" maxlength="10" data-msm-field-interaction-events="click" 
data-ng-change="returnedUserCheck()" required="required">

using the following i can enter the value but the box doesn't think that there is anything there and therefore wont validate and i have to manually click inot the text box:

IE.document.all("regnumber")(1).innerText = Reg
IE.document.all("regnumber")(1).setCapture
IE.document.all("regnumber")(1).Click
IE.document.all("regnumber")(1).releaseCapture
IE.document.getElementsByTagName("BUTTON")(7).Click

Any help would be greatly appreciated

ZigZigZig
  • 3
  • 5

2 Answers2

2

Try replacing:

IE.document.all("regnumber")(1).innerText = Reg

With:

IE.document.all("regnumber")(1).value = Reg

The value attribute specifies the value of an <input> element

The value attribute is used differently for different input types:

  • For "button", "reset", and "submit" - it defines the text on the button

  • For "text", "password", and "hidden" - it defines the initial (default) value of the input field

  • For "checkbox", "radio", "image" - it defines the value associated with the input (this is also the value that is sent on submit)

Note: The value attribute cannot be used with <input type="file">.

Edit:

It looks as if it's using angular to check the value has changed. Specifically, this attribute on the input element:

data-ng-keyup="inputChange=true; regnumberNotFound=false; carLookupButtonSubmitted=false"

It appears that you would need to also trigger a keyup event, which will likely require something like the following:

IE.document.all("regnumber")(1).Focus()
IE.document.all("regnumber")(1).Value = Reg + "." 'extra full stop will be removed on the next line
SendKeys "{BS}"

However, SendKeys is usually frowned upon unless absolutely necessary.

It may be worth trying to "trick" the form to recognise the value change by forcing the blur event to occur. This can be done by setting the focus to the input box, then setting the focus to another element, as follows:

IE.document.all("regnumber")(1).Focus()
IE.document.all("regnumber")(1).innerText = Reg
IE.document.getElementsByTagName("BUTTON")(7).Focus()
IE.document.getElementsByTagName("BUTTON")(7).Click

I'd recommend trying this suggestion before going down the SendKeys route

Sk93
  • 3,676
  • 3
  • 37
  • 67
  • Hi thanks for your input but alas I have the same issue, when i click the button it still thinks that the text box is empty. – ZigZigZig Nov 12 '15 at 09:48
  • Thanks, but these too don't fire the event correctly, I've tried shifting focus off and back on, I've tried to firing events and the only thing that works is a good old fashioned mouse click! – ZigZigZig Nov 12 '15 at 12:10
1

I was having similar trouble with a form and I found this:

VBA interaction with internet explorer

Which helped me solve the exact same type of problem!

The trick was to use

Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long

At the top of the Module, then modify your code to the following:

Dim HWNDSrc As Long
HWNDSrc = ie.HWND
SetForegroundWindow HWNDSrc
IE.document.all("regnumber")(1).Focus()
IE.document.all("regnumber")(1).Value = Reg + "." 'extra full stop will be removed on the next line
Application.SendKeys "{BS}"
casewolf
  • 190
  • 10