【问题标题】:Find the button but can't click it找到按钮但无法点击
【发布时间】:2018-01-11 07:12:36
【问题描述】:

我尝试运行的 SDK 首先有一个准备安装步骤,然后显示下一步按钮。所以我一直等到看到按钮。

当下一个按钮出现时,ConsolWrite 在循环中写入。但我无法点击按钮。也试过 send("!n") 还是不行。

 #include <GUIConstantsEx.au3>

Global $hCtrl = 0, $Waiting = True

$wintitle = "SigCaptureWeb SDK - InstallShield Wizard"
ShellExecute("C:\SigCaptureWeb.exe")

; your GUI loop
While (1)
    If $Waiting And WinExists($wintitle) Then
        $hCtrl = ControlGetHandle($wintitle, "", "[CLASS:Button; TEXT:&Next >]")
        If $hCtrl Then
            ; we got the handle, so the button is there
            ; now do whatever you need to do
            ConsoleWrite("in the loop")
            ControlClick($wintitle,"", "[CLASS:Button; TEXT:&Next >]","{ENTER}")
            $Waiting = False
        EndIf
    EndIf

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

【问题讨论】:

  • ControlClick 控制鼠标,而不是键盘。将"{ENTER}" 替换为"primary" 或跳过该参数以使用默认"left"
  • @Stephan 是我尝试过的东西的遗留物。我之前跳过了,也没有用。

标签: autoit


【解决方案1】:

您可能需要以管理员身份运行脚本才能与以管理员身份运行的安装程序进行交互。

使用ShellExecute 测试 AutoIt 安装程序允许脚本检测窗口,尽管单击按钮不起作用,因为脚本以非管理员身份运行。这可以被认为是操作系统的一项安全功能,以保护管理进程。

这可能对你有用。我不确定你为什么有 gui 代码等,所以我把它排除在外。

; This is a compile directive to make the compiled script run as admin.
#pragma compile(ExecLevel, requireAdministrator)

; This directive is for uncompiled script to run as admin.
#RequireAdmin

$wintitle = "SigCaptureWeb SDK - InstallShield Wizard"
Run("C:\SigCaptureWeb.exe")

WinWait($wintitle)

; Wait for Next button to become visible.
While Not ControlCommand($wintitle, "", "&Next >", "IsVisible", "")
    Sleep(250)
WEnd

ControlClick($wintitle, "", "&Next >")

作为 InstallShield 安装程序,它可能具有参数,您可以将这些参数传递给可执行文件以启动静默安装,这可能会使其更容易。你可以调查一下。

【讨论】:

  • 不要认为管理员权限是问题所在。试过你的,但它不起作用。我使用 gui 的原因是因为窗口弹出但没有按钮。它有一个进度条,然后显示按钮。所以我想我必须等待并检查按钮可用,然后单击它。但它也不是:)
  • 如果需要延迟,那么controlcommand 可以获得控件的状态。我不知道此安装的行为,除了您告知的内容,如果我最初没有正确的代码,请原谅。 guigetmsg 等在你的代码中没有任何部分,所以我很困惑为什么它在那里。 sendcontrol* 函数需要是管理员才能与管理员进程一起操作,在怀疑之前给它一个机会。让它工作,然后尝试禁用管理指令并检查是否仍然工作。如果安装仅将文件添加到您的配置文件文件夹,则可能不需要管理员。不知道安装程序是否提示admin。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 2010-11-02
  • 1970-01-01
  • 2011-07-14
  • 2011-08-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多