在 IE 自动化中,如何处理通过 vbscript 单击“上传文件”或“附加”按钮时打开的窗口?
需要明确的是,我已经自动化,直到按下“上传”按钮。之后我需要填写文件路径,并且需要在新打开的窗口中自动按下打开按钮。这是使用 vbscript 或任何其他方式处理该窗口的任何方式吗?
在 IE 自动化中,如何处理通过 vbscript 单击“上传文件”或“附加”按钮时打开的窗口?
需要明确的是,我已经自动化,直到按下“上传”按钮。之后我需要填写文件路径,并且需要在新打开的窗口中自动按下打开按钮。这是使用 vbscript 或任何其他方式处理该窗口的任何方式吗?
You can use the Wscript Shell object to activate the dialog that is opened when a file upload is initiated. The process for bringing a window into focus looks like this. You'll need to adjust it accordingly to fit your code. Primarily, you need to supply the window title. I'm not on Windows right now to test, but it would typically be something like "Choose File to Upload"
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Visible = True
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate objExplorer.Name
Set objShell = Nothing
Set objExplorer = Nothing
You might also try using SendKeys without activating the window first. The browse dialog should be application modal. As long as your webpage tab is activated, it should have focus anyway. Don't forget that buttons can be pressed via their keyboard shorcuts as well.