【发布时间】:2019-09-12 02:18:13
【问题描述】:
我正在使用基于 Internet Explorer 的应用程序,我需要在其中检索只读输入文本框的值。我查看了其他 Stack Overflow 问题,没有看到任何有关获取只读或隐藏输入框的值的信息。我也没有在互联网上找到任何可以使用的东西。
这是我试图从中获取值的输入框的 HTML 代码:
<div class="col-xs-10 col-sm-9 col-md-6 col-lg-5 form-field input_controls">
<div class="hidden" ng-non-bindable="">
<input name="sys_original.x_opt_im_issue_task.number" id="sys_original.x_opt_im_issue_task.number" type="hidden" value="TSK0111065" />
</div>
<input class="form-control disabled " id="sys_readonly.x_opt_im_issue_task.number" readonly="readonly" ng-non-bindable="" value="TSK0111065" />
</div>
这是我试图用来获取无效输入文本框值的 VBScript 代码:
更新
Option Explicit
Dim WShell, objShell, objIE
Dim strMessage, URL, ErrMsg, URLFound, Browser
Dim EN_ID, EntNowID
Sub Main()
On Error Resume Next
Set WShell = CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")
If Err.Number <> 0 Then ShowError("Failed to create objects")
On Error GoTo 0
Check_EN
SetEverythingToNothing
End Sub
'---------------------------------
Sub ShowError(strMessage)
MsgBox strMessage & vbNewline & vbNewline & "Error number: " & Err.Number & vbNewline & "Source: " & Err.Source & vbNewline & "Description: " & Err.Description
Err.Clear
SetEverythingToNothing
End Sub
'------------------------------
Sub Check_EN()
URL = "https://enterprisenow.mysite.com"
ErrMsg = "EnterpriseNOW is not open or on the incorrect page. Please check & rerun the macro."
Check_URL
ErrMsg = ""
Set EN_ID = objIE.document.getElementById("sys_readonly.x_opt_im_issue_task.number")
EntNowID = EN_ID.Value
MsgBox EntNowID
End Sub
'------------------------------
Function Check_URL()
URLFound = False
For Each Browser In objShell.Windows()
If InStr(UCase(Browser.LocationURL), UCase(URL)) > 0 Then
If InStr(UCase(Browser.FullName), "IEXPLORE.EXE") Then
If Err.Number = 0 Then
Set objIE = Browser
URLFound = True
Exit For
End If
End If
End If
Next
If URLFound = False Then
MsgBox "Unable to find URL."
SetEverythingToNothing
End If
End Function
'-----------------------------
Sub SetEverythingToNothing()
Set WShell = Nothing
Set objShell = Nothing
Set Browser = Nothing
Set objIE = Nothing
End Sub
我可以设置objIE 对象并找到URL,但我收到的是"Run-time error '424': Object required"。是因为输入文本框是隐藏的还是只读的?我也想知道它是否与嵌套的div标签有关?
【问题讨论】:
-
看起来你的
objShell没有初始化。 -
objShell在代码顶部初始化为Set objShell = CreateObject("Shell.Application"),我只是没有将它包含在示例中以节省空间以提高可读性。此外,它必须被初始化,因为我可以找到URL,只是无法访问input字段中的数字。 -
足够完整是有帮助的,而且一定要清楚地指出哪里出错了。
-
我很抱歉。下次我必须记住这一点。当我说“我能够设置
objIE对象并找到URL...”时,我以为我在我的示例之后很清楚。我不相信我需要显示初始化objShell,因为它会在For...Next循环的开头显示错误。感谢您的建议。