如果 Internet Explorer 首次使用代碼啟動,則沒有問題。
如果網站已經登錄系統,我會得到一個錯誤
物件不支持...
如果網頁已經登錄,我想跳過這個登錄階段。
我使用的示例代碼
Sub Login()
Dim IE As New InternetExplorer, url As String
Dim Html As HTMLDocument, idCheck As Object
url = "https://abc-site.com/"
With IE
.Visible = True
.Navigate2 url
While .Busy Or .readyState < 4: DoEvents: Wend
Set Html = .document
End With
Set idCheck = Html.querySelector(".Log In")
If Not idCheck Is Nothing Then
Html.querySelector("[name=userName]").Value = "username"
Html.querySelector("[name=password]").Value = "password"
Html.querySelector("[type=submit]").Click
While IE.Busy Or IE.readyState < 4: DoEvents: Wend
Else
End If
End Sub
USER NAME
<input id="Content1_UserIDView_txtUserid_UiInput" ng-class="{'error' : AuthMethod.error}" type="text" class="form-control bb-input bb-username-input ng-pristine ng-scope ng-empty ng-invalid ng-invalid-required ng-touched" placeholder="User ID" autocomplete="off" ng-model="AuthMethod.user" ng-change="AuthMethod.getMethodOnChange(method.input.id)" ng-disabled="false" ng-if="method.label.text !== ' *' && method.input.id.length > 0" ng-init="AuthMethod.getUser()" tabindex="0" focus-if="" required="" aria-invalid="true">
PASSWORD
<input id="Content_UserIDView_tbxPassword_UiInput" ng-class="{'error' : AuthMethod.error}" type="password" class="form-control bb-input bb-password-input ng-pristine ng-scope ng-empty ng-invalid ng-invalid-required ng-touched" placeholder="Password" autocomplete="off" ng-model="AuthMethod.pass" ng-change="AuthMethod.getPassOnChange(method.input.id, $event)" ng-disabled="false" ng-if="method.label.text !== ' *' && method.input.id.length > 0" ng-init="AuthMethod.getPass()" tabindex="0" focus-if="AuthMethod.authMethodId[0].label.text.length === 0" required="" aria-invalid="true">
Login Button
<a href="#" class="btn-primary bb-binding" ng-disabled="UserIdButton.shouldDisableButton()" ng-click="!UserIdButton.shouldDisableButton() && UserIdButton.click(UserIdButton.userIdViewBtn.button.id)" title=" Log In" disabled="disabled">
Log In
</a>
uj5u.com熱心網友回復:
從鏈接中找到上述查詢的解決方案
If .querySelectorAll("#Content1_UserIDView_txtUserid_UiInput").length > 0 Then
'do login page stuff
Else
'Skip login code
End If
'proceed with the other code....
感謝 QHarr 它幫助了我并解決了我的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/418340.html
標籤:
