Я работаю над некоторой автоматизацией, в которой данные будут в excel и вам необходимо обновить поля на веб-сайте, используя значения excel. Я нашел этот макрос онлайн и попытался его отредактировать, но он не работает. Прошу совета, поэтому я могу продолжить с обновлением полей, как только логин будет успешным.VBA для заполнения webform
я добавил следующие РЕФЕРЕНТЫ:
- Microsoft HTML Object Library
- Microsoft Internet контролирует
Вопросы: Пробовал запустить его в IE8. Нужно ли обновлять IE 11? Поступила ошибка:
Method 'Document' of object 'IWebBrowser2' failed on line
Изменено: Я обновил к IE11 и теперь ошибка изменяется на
"Automation error, unspecified error"
IE.document.getelementsbyname("_58_login").Value = "jigarjigar"
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
Sub Automate_IE_Enter_Data()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim HWNDSrc As Long
Dim document As HTMLDocument
'Create InternetExplorer Object
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
'Set IE = CreateObject("InternetExplorer.Application")
'True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Navigate to URL
IE.Navigate https://www.asite.com/login-home/
' Wait while IE loading...
Do While IE.ReadyState = 4: DoEvents: Loop
'Get Window ID for IE so we can set it as activate window
HWNDSrc = IE.HWND
'Set IE as Active Window
SetForegroundWindow HWNDSrc
'Find & Fill Out Input Box
IE.document.getelementsbyname("_58_login").Value = "jigarjigar"
IE.document.getelementsbyname("_58_password").Value = "mypassword"
IE.document.getelementsbyclassname("btn-submit nobgcolor").Click
'Unload IE
endmacro:
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
<table class="lfr-table">
<tr>
<td class="label-unm">
Login (Email)
</td>
<td>
<div class="inp-login"><input name="_58_login" type="text" value="[email protected]" onblur="checkforGSUser(this)" autocomplete="off"/></div>
</td>
</tr>
<tr>
<td class="label-pass">
Password
</td>
<td>
<div class="inp-login"><input id="_58_password" name="_58_password" type="password" autocomplete="off" value="" /></div>
<span id="_58_passwordCapsLockSpan" class="pwdCapsMsgSpan" style="position:absolute;display:none;"><table width="111" border="0" cellspacing="0" cellpadding="0"><tr><td class="pwdCapsBorder"><img src="/html/themes/asite/images/common/caps_msg_arrow.gif" hspace="10" /></td></tr><tr><td class="pwdCapsMsg"> Caps Lock is on.</td></tr></table></span>
</td>
</tr>
</table>
<div class="div-submit"> </div>
<div class="div-login-link">
<input class="btn-submit nobgcolor" type="image" src="/html/themes/asite/images/common/login.gif" />
<a target="_self" href="https://portal.asite.com/widget/web/guest/home?p_p_id=58&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&_58_struts_action=%2Flogin%2Fview&_58_cmd=forgot-password">Forgot Password?</a>
<br/>
<a href="https://www.asite.com/contactus" target="_top">Don't have an account?</a>
<br/>
<div class="clear-all"></div>
<div class="clear-all"></div>
</div>
</form>
<script type="text/javascript">
вы пробовали .InnerText? –
В чем проблема? –