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 プロパティはありません。また、許可されていないと思われる同じ名前の要素を 2 つ以上持つことができることも意味します。

于 2012-11-29T17:21:19.903 に答える