0

我是 Powershell 的新手,我在这个问题上苦苦挣扎的时间比我愿意承认的要长。我正在尝试自动填写 Intranet 网络表单,我认为这将非常简单。我已经完成了登录组件,但是在填写表单上的“姓氏”文本框时遇到了麻烦。

$url = "www.myintranetsite.com"
$lastname="Smith" 
$firstname="John" 
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url); 
while ($ie.Busy -eq $true) 
{ 
Start-Sleep -Milliseconds 1000; 
} 
$ie.Document.getElementById("ERM_SEARCH_WRK_ERM_LAST_NAME_LBL").value = 
$lastname 

错误标记是我无法在空值表达式上调用方法。违规者是“ERM_SEARCH_WRK_ERM_LAST_NAME_LBL”

关于为什么 $lastname 会作为空值返回的任何建议?

![1]: https://i.stack.imgur.com/Jf8Ht.jpg ![2]: https://i.stack.imgur.com/pE71n.jpg

4

3 回答 3

0

您的问题是您尝试向标签添加值。

标签不包含值。

https://www.w3schools.com/TagS/tag_label.asp

根据您的图片,该标签似乎适用于ERM_SEARCH_WRK_ERM_LAST_NAME

$url = "www.myintranetsite.com"
$lastname="Smith" 
$firstname="John" 
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url); 
while ($ie.Busy -eq $true) 
{ 
Start-Sleep -Milliseconds 1000; 
} 
$ie.Document.getElementById('ERM_SEARCH_WRK_ERM_BO_NAME$542$').value = $lastname
于 2017-09-27T20:09:01.480 回答
0

问题不是姓氏。它是元素。你能做这样的事情吗?

$doc = $ie.document
$lastname = $doc.getElementById('ERM_SEARCH_WRK_ERM_LAST_NAME_LBL')
$lastname.Value = "smith"

并在元素 id 上使用单引号而不是双引号

定义 $lastname 对象后,检查其成员| get-member是否value为可用属性

于 2017-09-27T19:45:19.583 回答
0

尝试单击按钮时遇到相同的错误:

    $ie = new-object -com "InternetExplorer.Application"
    $ie.navigate("MyURL")
    $ie.visible = $true
    while ($ie.Busy -eq $true){  Start-Sleep -Milliseconds 1000;  }
    $doc = $ie.document
$btn=$doc.getElementByID('ctl00_PageHeader1_ctl06_c_b_Start_c_b_View_c_b_ExportDefaultButton_ExportDefaultButton')
    $btn.click()

错误是:“您不能在空值表达式上调用方法。”

视窗 10 x64

于 2022-01-04T20:26:56.257 回答