无法使用 AutoIt 从 Windows 窗体的下拉列表中选择值

发布于 2024-11-15 23:15:42 字数 862 浏览 3 评论 0原文

使用以下代码

ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "ShowDropDown")
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "This is my default value (TEST) - First")

or

ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "ShowDropDown")
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "select", "This is my default value (TEST) - First")

它选择组合框,但没有从列表中选择所需的“这是我的默认值(测试)- 首先”。基本上,它选择以 t 开头的任何值。例如,第一个值是“TMP”。因此,它不是完全匹配,而是选择任何第一个字符匹配。如何强制它从列表中选择确切的字符串?

我也尝试使用以下代码,但似乎没有任何效果。

WinWaitActive($title)
$Index = _GUICtrlComboBoxEx_FindStringExact($hcombo, $sText)
_GUICtrlComboBoxEx_SetCurSel($hcombo, $Index)
or following
WinWaitActive($title)
$Index = _GUICtrlComboBox_FindStringExact($hcombo, $sText)
_GUICtrlComboBox_SelectString($hcombo, $Index)

Using the following code

ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "ShowDropDown")
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "This is my default value (TEST) - First")

or

ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "ShowDropDown")
ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "select", "This is my default value (TEST) - First")

It selects the combo box, but it is not selecting the desired "this is my default value (TEST) - First" from the list. Basically, it is selecting any value that starts with t. For example, the first value is "TMP". So instead of exactly matching it is selecting any first character match. How do I force it to select the exact string from the list?

I also tried using the following code, but nothing seems to work.

WinWaitActive($title)
$Index = _GUICtrlComboBoxEx_FindStringExact($hcombo, $sText)
_GUICtrlComboBoxEx_SetCurSel($hcombo, $Index)
or following
WinWaitActive($title)
$Index = _GUICtrlComboBox_FindStringExact($hcombo, $sText)
_GUICtrlComboBox_SelectString($hcombo, $Index)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红尘作伴 2024-11-22 23:15:42

现在您使用的 ControlSend 参数不正确。下面将发送字符串“select”,最后一个参数将被评估为 0。

ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "select", "This is my default value (TEST) - First")

因为它期望 1 或 0 作为最后一个参数)。不用说这不是你想要的。

您应该使用 ControlCommand 执行类似 SelectString 的操作。您不必首先显示下拉列表:

ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "SelectString", "This is my default value (TEST) - First")

我无法对此进行测试,但只要它找到窗口并且字符串正确,那么就应该没问题。

Right now you are using ControlSend with incorrect parameters. The following will send the string 'select', and the last parameter will be evaluated to 0.

ControlSend("Test Form", "", "[NAME:ctlMsgQueueCombo]", "select", "This is my default value (TEST) - First")

As it expects 1 or 0 as the last parameter). Needless to say it's not what you want.

You should be doing something like SelectString with ControlCommand. You shouldn't have to show the dropdown first:

ControlCommand("Test Form", "", "[NAME:ctlMsgQueueCombo]", "SelectString", "This is my default value (TEST) - First")

I haven't been able to test that, but as long as it's finding the window and the string is correct then it should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文