我正在使用带有selenium的AutoIt工具。我正在做的是当我得到一个'另存为'我的应用程序中的对话框,我得到一些默认值,文件存储在我的系统中。我正在尝试将其重命名为“New'如下面的代码中所述。但是我在这里遇到的问题是,文件名被更改为' 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")
答案 0 :(得分:0)
它适用于此:
$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")
答案 1 :(得分:0)
但是我要问的问题是,文件名被更改为 在对话框中成功执行“新建”,但是当我单击“保存”时, 将使用默认文件名存储。
我花了一段时间,但最终为我的项目弄清楚了,希望有人可以从中受益。原来,文件夹路径的地址栏是(工具栏按钮和编辑框)的组合。我不知道实际的结构,但我想像的方式是;编辑框嵌套在ToolbarWindow32中。单击地址栏(ToolbarWindow32)手动输入自己的路径后,将激活编辑框。想象一下,ToolbarWindow32是父级,而Edit框是子级。有知识的人请对此有所了解。
这是一个工作示例,具有完成同一件事的不同方法。
#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