【问题标题】:Renaming filename in save as dialog box using autoit with selenium使用带有 selenium 的 autoit 在另存为对话框中重命名文件名
【发布时间】:2016-11-30 01:46:39
【问题描述】:

我正在使用带有 selenium 的 AutoIt 工具。我正在做的是当我在我的应用程序中得到一个“另存为”对话框时,我得到了一些默认值,文件存储在我的系统中。我正在尝试将其重命名为“新”,如下面的代码中所述。但我遇到的问题是,文件名在对话框中成功更改为“新建”,但是当我点击“保存”时,它会以默认文件名存储。

$windowHandle = WinGetHandle("Enter name of file to save to…")
WinActivate($windowHandle)
ControlSetText("Enter name of file to save to…", "", "Edit1", "New")
ControlClick("Enter name of file to save to…", "", "Button1")

【问题讨论】:

  • 尝试点击ControlSetText之后的Edit1。
  • @Milos,我尝试了你的建议,但没有成功

标签: java selenium autoit


【解决方案1】:

它适用于这个:

$windowHandle = WinGetHandle("Enter name of file to save to…")
WinActivate($windowHandle)

ControlSetText("Enter name of file to save to…", "", "Edit1", "2131221")
ControlClick("Enter name of file to save to…", "", "Edit1")
ControlSetText("Enter name of file to save to…", "", "Edit1", "5666")
ControlClick("Enter name of file to save to…", "", "Edit1")
ControlSetText("Enter name of file to save to…", "", "Edit1", Send( "  {BACKSPACE}" ))
ControlSetText("Enter name of file to save to…", "", "Edit1", "New")
ControlClick("Enter name of file to save to…", "", "Button1")

【讨论】:

    【解决方案2】:

    但我在这里遇到的问题是,文件名更改为 对话框中的“新建”成功,但是当我单击“保存”时,它 以默认文件名存储。

    我花了一段时间,但最终为我的项目弄明白了,希望有人能从中受益。事实证明,文件夹路径的地址栏是(工具栏按钮和编辑框)的组合。我不知道实际的结构,但我想象它的方式是;编辑框嵌套在 ToolbarWindow32 内。当点击地址栏 (ToolbarWindow32) 手动输入您自己的路径时,编辑框被激活。想象 ToolbarWindow32 是父级,编辑框是子级。任何有知识的人请对此有所了解。

    这是一个工作示例,它使用不同的方式来完成同一件事。

        #include <GuiToolbar.au3>
        #Include <File.au3>
    
    
        TestChangeSaveAsAddress()
    
        Func TestChangeSaveAsAddress()
    
            Run('Notepad.exe')
            WinWaitActive('Untitled - Notepad')
            Send('new line.')
            Send('^s')
    
    
            Local $AddressPath = 'K:\_DOC\_TEXT'
            Local $aFileName = 'New File.txt'
            ClipPut($AddressPath)                    ;for  Option 1
    
            Local $SaveAsTitle = '[CLASS:#32770; TITLE:Save As]'
    
    
        # I.a
    
            ;get 'Save As' window handle
            Local $hWnd = WinWaitActive($SaveAsTitle, '&Save', 10)
    
        # I.b
    
            ;get Address Bar handle for $AddressPath
            Local $hTollbars = ControlGetHandle($hWnd, 'Address', '[CLASSNN:ToolbarWindow324]')
    
    
        # II - IMPORTANT: Address Bar must be infocus in order to activate Edit2 to set $AddressPath in step (IV)
               ;Option 2 or 3 is highly recommended
    
    
            # ;Option 1 - Select ToolbarWindow32 - Address Bar (work around -not recomended)
            #------------------------------------------------------------------------------
        ;~         ControlFocus($hTollbars, 'Address', '')
        ;~         ControlSend($hTollbars, 'Address', '','{SPACE}')
        ;~         Send('^v{ENTER}')
    
            # ;Option 2 - Select ToolbarWindow32 - Address Bar (same as Option 3)
            #-------------------------------------------------------------------
                 ControlCommand($hTollbars, "Address", "", "SendCommandID", 1280)
    
            # ;Option 3 - Select ToolbarWindow32 - Address Bar (same as Option 2)
            #------------------------------------------------------------------------------------------
        ;~         ControlCommand($hWnd, "Address", "ToolbarWindow324", "SendCommandID", 1280)
    
            # ;Option 4 - Select ToolbarWindow32 - Address Bar (mouse pointer also relocated)
            #------------------------------------------------------------------------------------------
        ;~        _GUICtrlToolbar_ClickIndex($hTollbars, -1,'Left',True,1,0)
    
            # ;Option 5 - Select ToolbarWindow32 - Address Bar (this simulate as Run, NOT RunWait if your project required it - NOT Recommended)
            #------------------------------------------------------------------------------------------
        ;~      Run(@AutoItExe & ' /AutoIt3ExecuteLine "ControlCommand ( hwnd(' & $hWnd & '),'''', hwnd(' & $hTollbars & '), ''SendCommandID'', 1280 )"')
    
    
        # III
                ;check if path $AddressPath exists
                If Not FileExists($AddressPath) Then DirCreate($AddressPath)
    
        # IV
                ;set new path
                ControlSetText($hWnd, "Address", 'Edit2', $AddressPath)
        ;~         ControlFocus($hTollbars,'Address','')
    
    
        # V
                ;commit new Path
                ControlSend($hWnd, "Address", 'Edit2','{ENTER}')
    
        # VI
                ;set new file name
                ControlSetText($hWnd, "Namespace", "Edit1", $aFileName)
                ControlFocus($hWnd,'Namespace','Edit1')
    
        # VII
                ;allow manual keypress {SPACE} or {ENTER} to save/cancel
        ;~         ControlFocus($hWnd,'&Save','Button1')
        ;~         ControlFocus($hWnd,'Cancel','Button2')
    
        # VIII
                ;auto click save/cancel
        ;~         ControlClick($hWnd,"&Save", 'Button1','Left')
        ;~         ControlClick($hWnd,"Cancel", 'Button2','Left')
    
    
        # IX
            #--------------------------------------------------
            # ---OR--- skip all above steps and use this work around
            #--------------------------------------------------
        ;~     ControlSetText($hWnd, "Namespace", "Edit1", $AddressPath&'\'&$aFileName)
    
        EndFunc
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多