2013-08-23 65 views
0

我想设置脚本以登录到特定的SolarWinds显示屏查看并不断刷新页面,每30秒钟一次。我已经检查了其他几个代码示例,但我看起来不错,但它不起作用。打开网站并登录,同时每30秒刷新一次页面

我的问题: 自动登录不起作用,没有任何内容输入到字段中,并且登录按钮没有被点击。 我也无法弄清楚如何刷新页面而不是每次打开一个新页面。

任何帮助表示赞赏!

这里是我的代码:

$Run = 1 

do { 

#Create the IE com object to be used for logging into SAM 
$ie = new-object -com InternetExplorer.Application 
$ie.visible = $true 
$ie.ToolBar = $false 
#$ie.Width = 1300 
#$ie.Height = 1000 
$ie.FullScreen = $true 
$ie.Left = 0 
$ie.Top = 0 
$SolarWinds = "http://SolarWindsServer/Orion/Login.aspx" 
$username = "username" 
$password = "password" 

$ie.navigate($SolarWinds) 
do { 
    Sleep 1000 
    }while ($ie.Busy -eq "True") 

sleep 30 

#Find the username field and enter username 
$ie.Document.getElementById('ctl00_BodyContent_Username').value = $username; 

#Find the password field and enter password 
$ie.Document.getElementById('ctl00_BodyContent_Password').value = $password; 

#Find and click the submit button 
$ie.Document.getElementById('SiteLoginText').submit() 

do { 
    Sleep 5 
    }while ($ie.Busy -eq "True") 

sleep 30 
}while ($Run -eq 1) 

的第一件事情,我得到这些错误,因此出现登录不工作:

你不能调用一个空值表达式的方法。 在C:\ Users \ me \ Desktop \ SAMTEST.ps1:25 char:28 + $ ie.Document.getElementById < < < <('ctl00_BodyContent_Username')。value = $ username; + CategoryInfo:InvalidOperation:(的getElementById:字符串)[],的RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull

不能调用上一个空值表达的方法。 在C:\ Users \ me \ Desktop \ SAMTEST.ps1:28 char:28 + $ ie.Document.getElementById < < < <('ctl00_BodyContent_Password')。value = $ password; + CategoryInfo:InvalidOperation:(的getElementById:字符串)[],的RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull

不能调用上一个空值表达的方法。 在C:\用户\我\桌面\ SAMTEST.ps1:31字符:28 + $ ie.Document.getElementById < < < <( 'SiteLoginText')提交() + CategoryInfo:InvalidOperation:(的getElementById:字符串)[],RuntimeException的 + FullyQualifiedErrorId:InvokeMethodOnNull

下面是代码的网页源代码片段:

<div id="gutter"> 
    <div id="dialog"><span class="crn crn-tl"></span><span class="crn crn-tr"></span><span class="crn crn-bl"></span><span class="crn crn-br"></span> 
     <img id="logo" src="/orion/images/login_logo.png" width="182" height="50" alt="SolarWinds" /> 



     <div> 
      <label for="username">User name:</label><div><input name="ctl00$BodyContent$Username" type="text" id="ctl00_BodyContent_Username" tabindex="1" automation="username" /></div> 
     </div> 

     <p class="sw-pg-suggestion">Enter domain\username or [email protected] for windows accounts</p> 

     <span id="ctl00_BodyContent_ctl04" class="sw-pg-errortext sw-validation-error" style="display:none;"> 
      <p>User name is required.</p> 
     </span> 

     <div> 
      <label for="password">Password:</label><div><input name="ctl00$BodyContent$Password" type="password" id="ctl00_BodyContent_Password" tabindex="2" automation="password" /></div> 
     </div> 



     <div class="sw-btn-bar"> 
      <a tabindex="3" class=" sw-btn-primary sw-btn" automation="Login" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$BodyContent$ctl05&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))"><span class="sw-btn-c"><span class="sw-btn-t">Login</span></span></a> 
     </div> 
    </div> 




    <div id="CookiesNotWorking" class="sw-pg-errortext sw-pg-align" style="display:none;"><p>Enable cookies to login</p></div> 
    <noscript><div class="sw-pg-errortext sw-pg-align"><p>Enable JavaScript to login</p></div></noscript> 

    <p id="SiteLoginText"></p> 
</div> 
+0

你有版本2,3,或4(beta)的PowerShell? – Colyn1337

+0

v2是运行的服务器已安装。它是仅用于投影仪屏幕的Windows XP Pro SP3服务器。 – bbinnebose

回答

相关问题