我正在尝试自动化用户从网站下载文件提取的过程。我的问题是,一旦单击“导出”按钮,就会出现一个 javascript 弹出窗口,其中包含提取的各种日期参数以及需要单击的最终“下载”按钮。在此 javascript 弹出窗口期间出现问题。单击导出按钮并打开弹出窗口后,powershell 似乎在脚本期间冻结,并且不允许执行任何进一步的命令。
我已经尝试使用 WASP 模块和 SELECT-WINDOW 来获取正确的 IE 进程窗口,但是 'Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | 选择 - 前 1 | Set-WindowActive' 命令将不会执行,因为在单击初始“导出”按钮后(弹出窗口打开时),Powershell 会立即卡住“运行脚本”。有没有一种方法可以在打开弹出框后“刷新”Powershell以执行进一步的命令,或者有什么想法可以打破我陷入这个Javascrip弹出窗口的连续“运行脚本”循环窗户?
# Set access URL and Credentials
$WebU='username'
$WebP='password'
$URLlogin='http://websiteurl.com'
$IEwait="1000"
# Execute IE and navigate to URL
$ie = New-Object -com "InternetExplorer.application";
$ie.visible = $True;
$ie.navigate($URLlogin);
Try{
# Login steps
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("txtLogin"))
{ $ie.Document.getElementByID("txtLogin").value = $WebU }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("txtPassword"))
{ $ie.Document.getElementByID("txtPassword").value = $WebP }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("btnLogin"))
{ $ie.Document.getElementByID("btnLogin").Click() }
# Navigate through website to find the 'Export' button
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("managementMenu_btnLearningResults"))
{ $ie.Document.getElementByID("managementMenu_btnLearningResults").Click() }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
# This is the part that freezes the script. Once the 'btnExport' button is clicked, a JS popup keeps Powershell from executing any additional commands
if ($ie.Document.getElementByID("btnExport"))
{ $ie.Document.getElementByID("btnExport").Click() }
# Once the popoup box opens, sending the 'ENTER' key should automatically download the export file
Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select -First 1 | Set-WindowActive
Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select-childwindow | Send-Keys "{ENTER}"
}
# These won't execute because the JS popup window confuses Powershell and keeps it in a continuous 'Running Script' process
Catch {
"Error" }
Finally {
"Now able to execute further commands" }