【问题标题】:check to see if the website is up and running from powershell检查网站是否已从 powershell 启动并运行
【发布时间】:2012-06-05 16:56:00
【问题描述】:

我正在尝试登录一个网站并查看它是否已启动并运行,下面是我的 powershell 代码和错误。有人可以让我知道我在哪里做错了。

$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")

..以及我在下面的 value 属性中遇到的错误

在此对象上找不到属性“值”;确保它存在并且是可设置的。 在 E:\XXXX\YYY_YY\test.ps1:12 char:12 + $LoginName.v

你好,

我尝试在 MSDN 文章的帮助下为我的简单要求编写以下内容,其中我有登录站点,其中登录页面要求输入用户 ID 和密码。我需要捕获成功返回页面并通过电子邮件发送给该组,说该网站已启动并正在运行,否则它已关闭,还要添加的一件事是我需要每半小时运行一次,任何帮助将不胜感激。以下是我的代码和错误以及我面临的错误

代码

$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()

错误

您不能在空值表达式上调用方法。 在 C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:7 char:27 + $tb1 = $doc.getElementByID

您不能在空值表达式上调用方法。 在 C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:9 char:27 + $tb2 = $doc.getElementByID

您不能在空值表达式上调用方法。 在 C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:11 char:27 + $btn = $doc.getElementByID

在此对象上找不到属性“值”;确保它存在并设置 桌子。 在 C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:13 char:6 + $tb1。

在此对象上找不到属性“值”;确保它存在并设置 桌子。 在 C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:15 char:6 + $tb2。

您不能在空值表达式上调用方法。 在 C:\Documents and Settings\k082504\MyScripts\CMM_Login.ps1:17 char:11 + $btn.click

【问题讨论】:

标签: powershell


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 2012-09-18
    • 2016-05-23
    • 2012-08-18
    • 2011-07-10
    相关资源
    最近更新 更多