Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用autoit和selenium在“另存为”对话框中重命名文件名_Java_Selenium_Autoit - Fatal编程技术网

Java 使用autoit和selenium在“另存为”对话框中重命名文件名

Java 使用autoit和selenium在“另存为”对话框中重命名文件名,java,selenium,autoit,Java,Selenium,Autoit,我正在使用selenium的AutoIt工具。我正在做的是,当我在应用程序中获得一个“另存为”对话框时,我会得到一些默认值,文件将使用这些默认值存储在我的系统中。我正在尝试将其重命名为“New”,如下面代码中所述。但我在这里遇到的问题是,文件名在对话框中成功更改为“新建”,但当我单击“保存”时,它将以默认文件名存储 $windowHandle = WinGetHandle("Enter name of file to save to…") WinActivate($windowHandle) C

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

$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")
它是这样运作的:

$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")
但我在这里遇到的问题是,文件名被更改为 对话框中的“新建”成功,但当我单击“保存”时 使用默认文件名存储

$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")
我花了我一段时间,但最终为我的项目找到了答案,希望有人能从中受益。原来文件夹路径的地址栏是(工具栏按钮和编辑框)的组合。我不知道实际的结构,但我想象它的方式;编辑框嵌套在ToolbarWindow32中。当单击地址栏(Toolbar Window32)手动输入您自己的路径时,编辑框被激活。假设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
#包括
#包括
TestChangeSaveAsAddress()
Func TestChangeSaveAsAddress()
运行('Notepad.exe')
WinWaitActive('无标题-记事本')
发送('新行')
发送(“^s”)
本地$AddressPath='K:\\文件\文本'
本地$aFileName='New File.txt'
ClipPut($AddressPath);选择1
本地$SaveAsTitle='[类:#32770;标题:另存为]'
#内华达州
    ;获取“另存为”窗口句柄
本地$hWnd=WinWaitActive($SaveAsTitle,&Save',10)
#I.b
    ;获取$AddressPath的地址栏句柄
本地$hTollbars=ControlGetHandle($hWnd,'Address','[CLASSNN:ToolbarWindow324]'))
#II-重要提示:地址栏必须是infocus,以便在步骤(IV)中激活Edit2以设置$AddressPath
;强烈建议选择2或3
    # ;选项1-选择工具栏Window32-地址栏(变通方法-不推荐)
    #------------------------------------------------------------------------------
;~ ControlFocus($hTollbars,'Address','')
;~ ControlSend($hTollbars,'Address',''''{SPACE}'))
;~ 发送(“^v{ENTER}”)
    # ;选项2-选择工具栏Window32-地址栏(与选项3相同)
    #-------------------------------------------------------------------
ControlCommand($hTollbars,“地址”,“发送命令ID”,1280)
    # ;选项3-选择工具栏窗口32-地址栏(与选项2相同)
    #------------------------------------------------------------------------------------------
;~ ControlCommand($hWnd,“地址”,“工具栏窗口324”,“发送命令ID”,1280)
    # ;选项4-选择工具栏Window32-地址栏(鼠标指针也重新定位)
    #------------------------------------------------------------------------------------------
;~点击索引($hTollbars,-1,'Left',True,1,0)
# ;选项5-选择工具栏Window32-地址栏(此选项模拟为运行,而不是运行等待,如果您的项目需要它-不推荐)
#------------------------------------------------------------------------------------------
;~      运行(@AutoItExe&'/AutoIt3ExecuteLine“控制命令(hwnd('&$hwnd&'),'',hwnd('&$hTollbars&'),''SendCommandID'',1280'))
#三,
        ;检查路径$AddressPath是否存在
如果文件不存在($AddressPath),则DirCreate($AddressPath)
#四,
        ;开辟新的道路
ControlSetText($hWnd,“Address”,'Edit2',$AddressPath)
;~ 控制焦点($hTollbars,'Address','')
#五
        ;提交新路径
ControlSend($hWnd,“Address”,'Edit2','{ENTER}'))
#六
        ;设置新文件名
ControlSetText($hWnd,“名称空间”,“Edit1”,“$aFileName)
ControlFocus($hWnd,'Namespace','Edit1'))
#七
        ;允许手动按键{SPACE}或{ENTER}保存/取消
;~ 控制焦点($hWnd,&Save','Button1'))
;~ 控制焦点($hWnd、'Cancel'、'Button2')
#八
        ;自动单击保存/取消
;~ 控制单击($hWnd,&Save,'Button1','Left')
;~ 控制点击($hWnd,“取消”,“按钮2”,“左”)
#九
    #--------------------------------------------------
#---或---跳过以上所有步骤,使用本练习
    #--------------------------------------------------
;~ ControlSetText($hWnd,“名称空间”,“Edit1”,“$AddressPath&'\'和$aFileName)
EndFunc

尝试在ControlSetText之后单击Edit1。@米洛斯,我尝试了你的建议,但没有成功