2017-05-03 6 views
0

私はPowerShellを使用してログインフォームを自動化したい:RAN後

<form method="post" class="login-form" name="loginForm" action="/Service/WebObjects/Service.woa/wo/0.15.7.3.1"> 
<label>Username</label> 
<input maxlength="128" style="width: 240px;" type="text" name="username" /> 
<label>Password</label> 
<input maxlength="64" style="width: 240px;" type="password" name="password" /> 
<input class="login-check-input" type="checkbox" name="rememberCheckBox" value="15.7.3.1.15" /> 
<label class="login-check-label" for="flag_stay_logged_in">Remember login</label><br/> 
<noscript> 
You need a JavaScript enabled browser to use this application. 
</noscript> 
<script language="javascript" type="text/javascript"> 
document.write('<div class="buttonBar"><input alt="Login" class="button" type="submit" value="Login" name="ButtonLogin" /></div>'); 
</script> 
</form> 

$ie=New-Object -comobject InternetExplorer.Application 
$ie.visible=$true 
$ie.ParsedHtml 
$ie.Navigate("https://livetime/Service/WebObjects/Service") 
while($ie.busy){Start-Sleep 1} 

$ie.Document.getElementById("username").value="my username " 
$ie.Document.getElementById("password").value="my password " 
$ie.Document.getElementById('ButtonLogin').click() 

このスクリプト私はこれらのエラーを取得:

The property 'value' cannot be found on this object. Verify that the property exists and can be set. 
At line:7 char:1 
+ $ie.Document.getElementById("username").value="mt username" 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : PropertyAssignmentException 

The property 'value' cannot be found on this object. Verify that the property exists and can be set. 
At line:8 char:1 
+ $ie.Document.getElementById("password").value="my password " 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : PropertyAssignmentException 

私が見つけたインターネットの例では、このスクリプトがうまくいくことがわかりました。

私は確認できるはずですか(異なる/古いバージョンまたは設定)ですか?

+0

あなたのHTMLページにいくつかの不具合がありますが、最も重要なのは、 'getElementById'をしたいのであれば、** id = **を定義するべきです。 は、私はあなたのHTMLページを簡単にするためにrecommentにちょうど:<!DOCTYPE HTML> ' \t \t \t \t \t <フォームメソッド= "ポスト" クラス= "ログイン・フォームの" 名前=」 loginForm "> \t \t \t \t <入力MAXLENGTH =" 128" スタイル= "幅:240ピクセル;"タイプ= "テキスト" ID = "ユーザ名" 名前= "ユーザ名" /> \t \t \t \t <入力MAXLENGTH = "64" スタイル= "幅:240ピクセル;"タイプ= "パスワード" ID = "パスワード" 名前= "パスワード" /> \t \t \t ' – iRon

+0

(コメントで)上記のHTMLページは私のために動作します。 HTMLページを変更できない場合は、 'getElementsByTagName'(' input')を使用してそれに応じて列挙します。 – iRon

+0

私はhtmlコードを変更できません。これ以上のものはページhtmlの一部ですが、ここでは「投稿による投稿」のみを示します。問題は$ ie.Document.getElementById( "username")。value = "my username"です。 $ ie.Document.getElementById ( "password")。value = "私のパスワード" $ ie.Document.getElementById( 'ButtonLogin')。click()は動作するはずのすべての例が表示されていても動作しません。私は何かが有効にされていない/インストールされていない、古いバージョンなどと思っている –

答えて

0

問題は、あなたが取得したい要素に定義されたIDがないことである(そこに定義されたですが、これは同じではありません!)。あなたに言及している例では、id属性も定義されていないことがわかります。 これは、1つの可能な方法は、入力を取得し、それに応じてそれらを列挙するgetElementsByTagNameのを使用することで、あなたが心配要素に別の方法を取得しなければならないことを意味:

$ie=New-Object -comobject InternetExplorer.Application 
$ie.visible=$true 
$ie.ParsedHtml 
$ie.Navigate("https://livetime/Service/WebObjects/Service") 
while($ie.busy){Start-Sleep 1} 
$document = $ie.Document 
$form = $document.forms[0] 
$inputs = $form.getElementsByTagName("input") 
($inputs | where {$_.name -eq "username"}).value = "my username" 
($inputs | where {$_.name -eq "Password"}).value = "my password" 

私は(私の簡素化テストページのために働くために、これを確認しています)のいずれかの定義された入力のためのIDを持たない:あなたはまだそれは私がここからアクセスすることはできません特定のウェブページ()で動作するように得ることができない場合は

<!DOCTYPE html> 
<html> 
    <head> 
    </head> 
    <body> 
     <form method="post" class="login-form" name="loginForm"> 
     <label>Username</label> 
     <input maxlength="128" style="width: 240px;" type="text" name="username" /> 
     <label>Password</label> 
     <input maxlength="64" style="width: 240px;" type="password" name="password" /> 
     </form> 
    </body> 
</html> 

、私は簡略化を構築することをお勧めいたしますHTMLページを自分で作成し、これをポータブルWebサーバー(例えばhttp://www.usbwebserver.net)。だから、同じページに文字どおり...