登录页面的字段未更新为已填写
fields of login page not updating as filled in
我正在尝试使用 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", False, True
evt3.initEvent "input", True, False
evt4.initEvent "change", True, 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 中的字段上,在开发者工具中,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
关注目标领域后。然后对密码做同样的事情。但它确实有效。
我正在尝试使用 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", False, True
evt3.initEvent "input", True, False
evt4.initEvent "change", True, 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 中的字段上,在开发者工具中,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
关注目标领域后。然后对密码做同样的事情。但它确实有效。