使用VBA将数据输入HTML5站点 [英] Entering data using VBA in to a HTML5 site

查看:122
本文介绍了使用VBA将数据输入HTML5站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要在下面的输入框中输入汽车注册:

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">

使用以下我可以输入值但该框不认为那里有任何东西因此不会验证,我必须手动点击文本框inot:

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

任何帮助将不胜感激

推荐答案

尝试更换:

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

使用:

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

attribute指定< input> 元素的值

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


value属性是我们对于不同的输入类型,编辑方式不同:

The value attribute is used differently for different input types:


  • 对于按钮, 重置和提交 - 它定义了
    按钮上的文字

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

对于text,password和hidden - 它定义了输入字段的初始
(默认值)

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

注意:value属性不能与< input type =file> 一起使用。

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

修改:

看起来好像是使用angular来检查值是否已更改。
具体来说,输入元素上的这个属性:

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"

您似乎还需要触发 keyup 事件,可能需要以下内容:

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}"

但是,除非绝对必要,否则SendKeys通常不赞成。

However, SendKeys is usually frowned upon unless absolutely necessary.

可能值得尝试欺骗表单通过强制 blur 要发生的事件。
这可以通过将焦点设置到输入框,然后将焦点设置为另一个元素来完成,如下所示:

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

我建议在按下 SendKeys 路线

这篇关于使用VBA将数据输入HTML5站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆