PowerShell通过IE中的名称以编程方式设置输入字段 [英] PowerShell programmatically set input field by name in IE

查看:59
本文介绍了PowerShell通过IE中的名称以编程方式设置输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关: Powershell:下载或保存源代码整个页面

我需要以编程方式驱动的输入字段没有ID,因此我尝试改用表单名称进行设置.

The input fields I need to programmatically drive do not have an ID, so I'm trying to set them with the form name instead.

在IE F12开发人员控制台中,此命令有效: document.forms["loginForm"].elements["_ssoUser"].value = "someone's username"

In the IE F12 developer console, this command works: document.forms["loginForm"].elements["_ssoUser"].value = "someone's username"

但是在PowerShell中,此命令失败: $ie.document.forms["loginForm"].elements["_ssoUser"].value = "$username"

But in PowerShell, this command fails: $ie.document.forms["loginForm"].elements["_ssoUser"].value = "$username"

错误是无法索引到空数组中".

The error is "cannot index into a null array".

推荐答案

最有可能是IFRAME中的表单,因此请按ID获取IFRAME,然后按ID获取表单,然后按如下名称选择子对象:(模拟输入密码)字段和登录按钮).

Most likely a form in an IFRAME so get the IFRAME by id then the form by ID then select the child object by the name like: (sim. for password field and login button).

($ie.document.getElementbyID("content").contentWindow.document.getElementbyID('loginForm') | Where-Object {$_.name -eq "_ssoUser"}).value = "username"

这篇关于PowerShell通过IE中的名称以编程方式设置输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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