You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cypress Enable脚本语句无法正常运行问题求助

Cypress Enable代码片段运行异常求助

我是一名技术文档工程师,梳理应用文档时发现现有Cypress Enable代码片段无法正常运行。我们的应用内置精简版VBA编辑器与编译器,测试部分语句未得到预期结果,甚至无任何反应,具体问题如下:

1. Declare语句的脚本未弹出预期对话框

测试代码:

Declare Function GetFocus Lib "User32" () As Integer
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (Byval hwnd As Long, Byval lpstring As String, Byval lpstrlen As Long)

Sub Main
   Dim hWindow%
   Dim str1 As String *51
   Dim str2 As String *25
   hWindow% = GetFocus()
   Print "GetWindowText returned: " & GetWindowText( hWindow%, str1, 51)
   Print "GetWindowText2 returned: " & GetWindowText( hWindow%, str2, 25)
   Print str1
   Print str2
End Sub

预期第一个Print语句会弹出标题为“Enable Scripting Language Editor”、内容为“GetWindowText returned: 50”的对话框,但实际无此效果。

2. DlgFocus语句测试中,点击OK/Cancel控件对话框都会直接关闭

测试代码:

Sub Main()
   Dim ListBox1$()
   Begin Dialog UserDialog ,,112,74,"Untitled",.DlgProc
      TextBox 12,20,88,12,.TextBox1
      OKButton 12,44,40,14
      CancelButton 60,44,40,14
      Text 12,11,88,8,"Enter Desired Salary:",.Text1
   End Dialog
   Dim d As UserDialog
   Dialog d
End Sub

Function DlgProc(ControlName$,Action%,SuppValue%) As Integer
   If Action% = 2 and ControlName$ = "OK" Then
      If IsNumeric(DlgText$("TextBox1")) Then
         Msgbox "Duly Noted."
      Else
         Msgbox "Sorry, you must enter a number."
         DlgFocus "TextBox1"
         DlgProc = 1
      End If
   End If
End Function

当输入非数字内容点击OK时,本应聚焦回TextBox1并不关闭对话框,但实际点击OK或Cancel按钮时对话框都会直接关闭。

3. DlgFocus测试代码中,点击任意控件返回值始终为0

测试代码:

Sub Main
   Begin Dialog UserDialog 200,120,"Script #9",.DialogFunc
      Text 10,10,180,15,"Please push the OK button"
      TextBox 10,40,180,15,.Text
      OKButton 30,90,60,20
      PushButton 110,90,60,20,"&Hello"
   End Dialog
   Dim dlg As UserDialog
   Print Dialog(dlg)
   MsgBox "Dialog info: " & Dialog(dlg)
End Sub

Function DialogFunc%(DlgItem$, Action%, SuppValue%)
   Print "Action=";Action%
   Select Case Action%
      Case 1 ' Dialog box initialization
         Beep
      Case 2 ' Value changing Or button pressed
         If DlgItem$ = "Hello" Then
            MsgBox "Hello"
            DialogFunc% = True 'Do Not Exit the Dialog
         End If
      Case 4 ' Focus changed
         Print "DlgFocus=""";DlgFocus();""""
         MsgBox "DlgFocus info: " & DlgFocus() & """"
      End Select
End Function

触发焦点变更事件(Action=4)时,调用DlgFocus()返回值始终为0,无法获取当前聚焦控件信息。

恳请各位提供技术帮助。


内容的提问来源于stack exchange,提问作者Steve R.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 02:30:52