使用 VBScript 检索只读输入文本框的值



>我正在使用一个基于 Internet Explorer 的应用程序,我需要检索只读输入文本框的值。我查看了其他堆栈溢出问题,但没有看到有关获取只读或隐藏输入框值的任何内容。我也没有找到任何可以在互联网上使用的东西。

这是我尝试从中获取值的输入框的 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标签有关?

尝试以下操作 - 它对我有用。 我注意到的是,如果我访问:

objIE.document.getElementById("sys_readonly.x_opt_im_issue_task.number").Value

不止一次,我收到错误:需要对象

但是,如果我使用"Set"并创建了一个这样的对象:

Set tasknumber = objIE.document.getElementById("sys_readonly.x_opt_im_issue_task.number")

然后,我可以多次访问该值而不会收到错误。

Option Explicit
Dim objShell : Set objShell = CreateObject("shell.application")
Dim URL : URL = "https://enterprisenow.mysite.com/"
Dim URLFound : URLFound = False
Dim Browser, tasknumber, tasknumbervalue
For Each Browser In objShell.Windows()
If InStr(UCase(Browser.FullName), "IEXPLORE.EXE") Then
If InStr(UCase(Browser.LocationURL), UCase(URL)) > 0 Then   
If Err.Number = 0 Then
Set tasknumber = Browser.document.getElementById("sys_readonly.x_opt_im_issue_task.number")
If (NOT IsNull(tasknumber) And NOT tasknumber Is Nothing) Then
tasknumbervalue = tasknumber.value
End If
Set tasknumber = Nothing                
Exit For
End If
End If
End If
Next
MsgBox tasknumbervalue
Set Browser = Nothing
Set objShell = Nothing

好吧,这不是我希望的解决方案,但它比尝试从input字段中获取数字更容易。

我有一种感觉,iframe标签可能会阻止我检测input字段 ID,所以我查看了iframe,发现input字段中的 TSK 号码也在iframe标签中。

而不是尝试这个:

EN_ID = objIE.document.getElementById("sys_readonly.x_opt_im_issue_task.number").Value

我能够使用它:

iframeName = Split(objIE.document.getElementById("gsft_main").Title, " | ")    'Title = "TSK0111065 | Issue Task | ServiceNow"
EN_ID = iframeName(0)

最新更新