internet-explorer - 进行自动化时调用 onkeyup 函数

标签 internet-explorer powershell automation

我正在尝试使用 PowerShell 执行 IE 自动化。在使用 IE 对象自动执行某些手动任务时,我可以导航到网站并在文本框中输入值,但只有在该文本框中触发按键事件后才能触发网站上可用的提交按钮。

<input id="txtFormID" class="TableTextAlt" type="text" onkeyup="doUpdate();"
  maxlength="10" name="txtFormID"></input>

有没有办法使用 PowerShell 脚本调用我的客户端页面的 doUpdate() 函数?

显然我无法在客户页面上编辑或进行任何更改。

注意:我不希望使用像 SendKeys 这样的方法来模拟击键,因为它不够健壮,并且需要 IE 窗口打开并聚焦。

最佳答案

如果您已经将事件/处理程序附加到元素 (onkeyup="doUpdate()"),您可以使用 fireEvent 以编程方式触发它元素上的方法:

$url = 'http://...'

$ie = New-Object -COM 'InternetExplorer.Application'
$ie.Navigate($url)
do { Start-Sleep -Milliseconds 100 } until ($ie.ReadyState -eq 4)
$ie.Visible = $true

$el = $ie.Document.getElementById('txtFormID')

$el.FireEvent('onKeyUp')

关于internet-explorer - 进行自动化时调用 onkeyup 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30692465/

相关文章:

testing - 无法滚动导航菜单

javascript - IE 中的 OffsetLeft 和 OffsetTop 问题

powershell - 内存使用 powershell 7.03 Foreach-object 并行

testing - 负载测试复合 C1 CMS 控制台

powershell - Powershell对where-object的奇怪行为

powershell - Foreach未处理每一项,而是尝试将全部处理为一行

windows - 当用户没有足够的权限时隐藏 COM-Server OLE 错误消息

internet-explorer - Internet Explorer 中的 jQuery 加载问题

asp.net - JQuery 源脚本导致 "A script on this page is causing Internet Explorer to run slowly."消息

internet-explorer - 为什么 IE11 开发者工具不起作用?