html - 跳过登录页面,如果已经登录
问题描述
如果 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>
解决方案
从链接中找到上述查询的解决方案
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 它帮助了我并解决了我的问题。
推荐阅读
- r - R在R中嵌套for循环,获取输出
- python - 制作一个程序来检测特定字典中的更改,如果有更改,则启动下一个代码
- node.js - 使用 PUT 方法(mysql2、sequelize、express)更改用户密码(bcrypt)
- c# - 使用 Entity Framework Core 将嵌套实体(如一对多)插入数据库
- virtual-machine - Proxmox,当内存使用量超过任意阈值时重新启动 VM
- python - Python在特定文件中搜索特定错误消息,但循环输出两次
- r - R中的平均坐标点?
- google-api - 谷歌日历事件 API 中的多个组织者
- javascript - 如何在 Mongodb 中使用 findOne 搜索对象内的值
- java - 在休眠中禁用持久性缓存