1

i'am trying to login to a web site and see it's up and running, below is my powershell code and the error. could somebody please let me know where am i doing wrong.

$ie = New-Object -ComObject "internetExplorer.Application" 
$ie.Visible = $true 
$ie.Navigate("https://www.Mysite.net/websuite/index.do"); 

while ($ie.Busy -eq $true){Start-Sleep -Milliseconds 20000}; 


$doc = $ie.Document 

$LoginName = $doc.getElementsByName("abcdef") 

$LoginName.value = "XXXXXX" 

$txtPassword = $doc.getElementsByName("123456")

$txtPassword = "XX_XXXXXX" 

$btnLogin = $doc.getElementsByName("cmdLogin")

..and the error i'am getting at the value property below

Property 'value' cannot be found on this object; make sure it exists and is settable. At E:\XXXX\YYY_YY\test.ps1:12 char:12 + $LoginName.v <<<< alue = "XXXXXXX"

Hello,

i tried writing the below for my simple requirement with the help of MSDN article, where i have login site with login page asking for UserId and Password. i need to capture the success return page and email to the group saying the website is up and running else it's down, one more thing to add this is i need to run every halfhour, Any help would be greatly appreciated. below is my code and errors and the errors i'am facing

code

$ie = new-object -com "InternetExplorer.Application"

$ie.navigate("https://www.Mysite.net/websuite/index.do")

$doc = $ie.document

$tb1 = $doc.getElementByID("TextBox1")

$tb2 = $doc.getElementByID("TextBox2")

$btn = $doc.getElementByID("Button1")

$tb1.value = "XXXXXX"

$tb2.value = "XXXX"

$btn.click()

errors

You cannot call a method on a null-valued expression. At C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:7 char:27 + $tb1 = $doc.getElementByID <<<< ("TextBox1") + CategoryInfo : InvalidOperation: (getElementByID:String) [], Ru ntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression. At C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:9 char:27 + $tb2 = $doc.getElementByID <<<< ("TextBox2") + CategoryInfo : InvalidOperation: (getElementByID:String) [], Ru ntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression. At C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:11 char:27 + $btn = $doc.getElementByID <<<< ("Button1") + CategoryInfo : InvalidOperation: (getElementByID:String) [], Ru ntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

Property 'value' cannot be found on this object; make sure it exists and is set table. At C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:13 char:6 + $tb1. <<<< value = "XXXXXX" + CategoryInfo : InvalidOperation: (value:String) [], RuntimeExce ption + FullyQualifiedErrorId : PropertyNotFound

Property 'value' cannot be found on this object; make sure it exists and is set table. At C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:15 char:6 + $tb2. <<<< value = "XXXXXX" + CategoryInfo : InvalidOperation: (value:String) [], RuntimeExce ption + FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression. At C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:17 char:11 + $btn.click <<<< () + CategoryInfo : InvalidOperation: (click:String) [], RuntimeExce

4

1 回答 1

0

我认为这是因为您的示例代码使用getElementByID(单数),而在您的代码中使用的是getElementsByName(复数)。如果确实存在调用该方法的方法,它将返回一个项目集合,因此它不会具有 value 属性。这也意味着您可以拥有两个或多个具有相同名称的元素,我认为这是不允许的。

于 2012-11-29T17:21:19.903 回答