登录页面的字段未更新为已填写

问题描述

我正在尝试使用VBA和IE自动化登录到网页。我在其他网站上找到了我能解决的问题,但不是这个网站。当我“单击”网站的登录按钮时,它告诉我用户名和密码为空,否则为空。我尝试过暂停。设置焦点,将该字段设置为活动和调度事件,但是到目前为止,该网站没有任何作用。

Dim HTMLInputs As MSHTML.IHTMLElementCollection
Dim HTMLInput As MSHTML.IHTMLInputElement
Dim HTMLInput2 As MSHTML.IHTMLInputElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection 
Dim HTMLButton As MSHTML.IHTMLButtonElement
Dim HTMLLinks As MSHTML.IHTMLElementCollection
Dim HTMLLink As MSHTML.IHTMLElement 

'make IE visible then open website
IE.Visible = True
'IE.top = 0
'IE.Left = 0
IE.width = 1200
IE.height = 800                                       '

IE.Navigate funcLookupURL(strMGA,strCO)                        'https://agency.hciharmony.com/login

'check if internet explorer is ready otherwise loop til it is
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
'    Debug.Print "1"
'    Debug.Print IE.Busy
    DoEvents
Loop
'login
Dim evt As Object
Dim evt2 As Object
Dim evt3 As Object
Dim evt4 As Object
Set evt = IE.Document.createEvent("HTMLEvents")
Set evt2 = IE.Document.createEvent("HTMLEvents")
Set evt3 = IE.Document.createEvent("HTMLEvents")
Set evt4 = IE.Document.createEvent("HTMLEvents")

evt.initEvent "blur",False,True
evt2.initEvent "focus",True
evt3.initEvent "input",True,False
evt4.initEvent "change",False 

'<input name="username" class="auth0-lock-input" type="text" placeholder="username/email" value="TTC-201" autocomplete="off" autocapitalize="off">
Set HTMLInput = IE.Document.querySelector("input[placeholder='username/email']") 

HTMLInput.focus
Sleep 500
HTMLInput.setActive
Sleep 500
HTMLInput.Value = funcLookupUserName(strMGA,strCO)
HTMLInput.setAttribute "value",funcLookupUserName(strMGA,strCO)
HTMLInput.innerText = funcLookupUserName(strMGA,strCO)

Sleep 500

'HTMLInput.dispatchEvent evt
'HTMLInput.dispatchEvent evt2
'HTMLInput.dispatchEvent evt3
'HTMLInput.dispatchEvent evt4

IE.Document.dispatchEvent evt
IE.Document.dispatchEvent evt2

IE.Document.dispatchEvent evt3
IE.Document.dispatchEvent evt4
Sleep 500

'<input name="password" class="auth0-lock-input" type="password" placeholder="your password" value="xxxsomevalueherexxx" autocomplete="off" autocapitalize="off">

Set HTMLInput2 = IE.Document.querySelector("input[placeholder='your password']")
HTMLInput2.focus
Sleep 500
HTMLInput2.setActive
Sleep 500
HTMLInput2.Value = funcLookupPassword(strMGA,strCO)             'password
HTMLInput2.innerText = funcLookupPassword(strMGA,strCO)             'password
HTMLInput2.setAttribute "value",funcLookupPassword(strMGA,strCO)            'password
Sleep 500
'HTMLInput2.dispatchEvent evt
'HTMLInput2.dispatchEvent evt2
'HTMLInput2.dispatchEvent evt3
'HTMLInput2.dispatchEvent evt4

IE.Document.dispatchEvent evt
IE.Document.dispatchEvent evt2
IE.Document.dispatchEvent evt3
IE.Document.dispatchEvent evt4
Sleep 500

'IE.Document.querySelector("input[placeholder='your password']").dispatchEvent evt

 
'i've tried submitting the form too instead of clicking the button
'IE.Document.Forms(0).submit

 
'Click sign in
Set HTMLButton = IE.Document.querySelector("button[type='submit']")
HTMLButton.focus
Sleep 500
HTMLButton.setActive
Sleep 3000
HTMLButton.Click
Debug.Print "Clicked Sign-in

我尝试提交表单,而不是单击按钮。那也不行。该代码尚未暂停以供网站加载,但我手动通过它,因此这不是我的问题。我看到该值出现在IE中的字段中,并且在deveoper工具中,该value属性用一个值填充。我已经在该字段以及IE.document上调度了事件。我试过的组合。我在此发布的上一个版本使用了模糊,更改,输入和聚焦。在我看来,事件侦听器主要位于主文档中。当我尝试登录时,这些值将从文本框中退出,并且它们以红色突出显示为“不能为空”。我对调度事件了解得很少,所以我主要是在这里猜测。任何建议将不胜感激。

编辑:

'topBlur
'  dispatchEvent: function (topLevelType,nativeEvent) {
'    if (!ReactEventListener._enabled) {
'      return;
'    }
'
'    var bookKeeping = TopLevelCallbackBookKeeping.getPooled(topLevelType,nativeEvent);
'    try {
'      // Event queue being processed in the same cycle allows
'      // `preventDefault`.
'      ReactUpdates.batchedUpdates(handleTopLevelImpl,bookKeeping);
'    } finally {
'      TopLevelCallbackBookKeeping.release(bookKeeping);
'    }
'  }
'};

此功能在单击登录按钮时触发。一切似乎都在说“ topblur”。不知道这意味着什么。 另外,当我输入用户ID时,此div更改为

改变了。然后在失去焦点时变回原位。

解决方法

因此,在尝试了许多方法之后,我剩下了VBA sendkeys作为答案。

HTMLInput.focus
Sleep 500
HTMLInput.setActive
Sleep 500
SendKeys strUname,True

关注目标领域后。然后对密码进行相同的操作。但这确实有效。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...