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

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

问题描述

我有一个自动为我的女儿一个特定的网站一个很好的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.

主要脚本使用Internet Explorer通过COM很像

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.

要解决这个问题我使用黄蜂这是一个开始另一个线程图书馆自动化窗户形式。在这个线程我只是坐在在一个循环中寻找确认提示,点击它。 (窗口在我的情况会弹出很多次)。在code此脚本看起来像这样

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
  }
}

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

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