使用PowerShell在IE中自动执行JavaScript确认提示 [英] Automating JavaScript confirmation prompt in IE using PowerShell

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

问题描述

我在HTML页面中有以下JavaScript代码:

I have the following JavaScript code in an HTML page:

<script language="javascript" type="text/javascript">
    function confirmAutoTransitionSelection() {
        var autoTransition = 'OFF';
        if (document.getElementById('autoTransitionON').checked) {
            autoTransition = 'ON';
        }
        return confirm('Are you sure you want to turn ' + autoTransition + ' the Auto Transition Setting?');
        }
</script>

在HTML代码中,我还有以下使用PowerShell脚本自动单击的输入按钮:

Also in the HTML code, I have the following input buttons that I'm auto-clicking with PowerShell script:

<form method="post">
Auto Transition
<input type="radio" id="autoTransitionON" name="autoTransition" checked value="true" /> ON
<input type="radio" name="autoTransition" value="false" /> OFF
<input class="submitBtn" type="submit" name="autoTransitionBtn" onclick="javascript:return confirmAutoTransitionSelection();" value="[Update]"/>
</form>

这是我的PowerShell脚本:

And here is my PowerShell script:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("http://localhost/test/")
While ($ie.Busy) {Sleep 2}
$doc = $ie.Document
$autobutton = $doc.getElementById("autoTransitionON").Click()
$btn = $doc.getElementsByTagName("input")
$autotransbtn = $btn | ? {$_.Name -eq "autoTransitionBtn"}
$autotransbtn.Click()
$ie.Quit()

使用PowerShell脚本自动单击输入按钮没有任何问题,但是JavaScript引发了一个确认,必须单击确认以确认更改.这是我遇到的问题.如何自动单击JavaScript确认?

I don't have any problems auto-clicking the input buttons with the PowerShell script, but the JavaScript is throwing a confirmation that has to be clicked to confirm the change. This is where I'm having a problem. How do I auto-click the JavaScript confirm?

提前谢谢!

推荐答案

我遇到了类似的问题,我基本上查询了该项的outerHTML属性以获取HTML代码.然后,您要做的就是将"confirm (*)"替换为"".之后,您可以将其设置回脚本中,然后单击它.

I ran into a similar problem, and I basically queried the outerHTML property of the item to get the HTML code. Then all you have to do is replace the "confirm (*)" with "". After that you can set it back into the script and then click it.

$Script = $IE.document.getElementsByTagName("script").item(#----------Whatever Number it is)
$Script.outerHTML = $Script.outerHTML | % {if ($_ -like "return confirm*") {"return true;"} else {$_}}
$autotransbtn.Click()

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

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