使用 Powershell 自动执行 IE 确认提示 [英] Automating IE confirmation prompt with Powershell

查看:36
本文介绍了使用 Powershell 自动执行 IE 确认提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的 powershell 脚本,可以为我女儿自动创建一个特定的网站.最近他们更改了站点并添加了一个不错的新功能,可以将我的脚本速度提高 10 倍.问题是他们用来激活此功能的输入类型会弹出一个确认对话框.HTML 看起来像这样

I have a nice powershell script that automates a particular website for my daughter. Recently they changed the site and added a nice new feature that would speed up my script by a factor of 10. The problem is the input type they use to activate this pops up a confirmation dialog. The HTML looks like this

<input type=submit name='enter_all' value='Enter all' onClick="return confirm('Enter all?');">

我可以在 powershell 中自动回答这个对话框吗?我希望脚本在后台运行,所以我认为发送击键已经结束.

Can I automate answering this dialog in powershell? I want the script to run in the background so I think sending keystrokes is out.

推荐答案

回答我自己的问题,但我确实找到了一种方法来做到这一点,即使它有点黑客.

Answering my own question but I did find a way to do this even if it is a bit of a hack.

主脚本通过 Com 使用 Internet Explorer,很像

The main script uses Internet Explorer via Com much like

$ie = new-object -com "InternetExplorer.Application"

有很多关于如何使用 ie com 对象进行导航、填写字段、单击按钮等的示例.但是,弹出确认只会导致挂断.

There are lots of examples on how to use the ie com object to navigate, fill in fields, click on buttons, etc, etc. However the pop up confirmation just causes things to hang up.

为了解决这个问题,我开始使用 Wasp 这是一个自动化库窗体.在这个线程中,我只是坐在一个循环中寻找确认提示并单击它.(在我的情况下,该窗口会弹出多次).这个脚本的代码看起来像这样

To get around this I started another thread using Wasp which is a library for automating windows forms. In this thread I just sit in a loop looking for the confirmation prompt and click on it. (The window pops up many times for in my case). The code for this script looks like this

   Import-Module WASP
while ($true) {
  [System.Threading.Thread]::Sleep(200) 
  $confirmation = Select-Window iexplore 
  if ($confirmation -ne $null) {
    Select-ChildWindow  -Window $confirmation | Select-Control -title "OK" -recurse | Send-Click
  }
}

这篇关于使用 Powershell 自动执行 IE 确认提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆