2015-02-06 42 views
0

我有一個簡單的問題和解答webfrom有來源是這樣的:PowerShell的 - IE對象,錯誤時設定值

<label for="question1" data-role="question-label"> 
    1. What&#39;s going well? Any wins (big or little) this week? 
</label> 
<div class="row answer-list"> 
    <div class="col-xs-12 col-sm-12"> 



     <div class="row" data-role="answer-box-item"> 
      <div class="col-xs-12 col-sm-9" data-role="answer-box-content-wrapper"> 
       <span class="edit-textile-notifications"> 
        <span class="glyphicon glyphicon-ok ok-status"></span> 
        <span class="not-sent-answer hidden" data-style="zoom-out">not sent</span> 
       </span> 
       <p type="text" class="edit-textile form-control input-sm answer-box-content" placeholder="create new answer" data-answer="true" data-question-id="1" data-role="new-answer-form"></p> 

      </div> 
      <div class="col-xs-12 col-sm-3 answer-actions-wrapper" style="display: none;"> 
       <div class="btn-group btn-group-sm answer-actions" > 
        <button type="button" class="btn btn-default answer-delete ladda-button" title="remove answer" data-style="zoom-out"> 
         <span class="ladda-label"> 
          <span class="glyphicon glyphicon-remove"></span> 
         </span> 
        </button> 

我試圖填補使用PowerShell這份表單。但我的代碼dosn't工作

cls 
$ie = new-object -com "InternetExplorer.Application" 
Start-Sleep -Seconds 1 
$ie.Navigate("https://test.contoso.internal") 
Start-Sleep -Seconds 1 
$doc = $ie.Document 
$questions = $doc.body.getElementsByClassName("edit-textile form-control input-sm answer-box-content") 
foreach ($questions in $questions) { 
if ($question -like "data-question-id="1"") {$question.value = "Answer 1"} 
if ($question -like "data-question-id="2"") {$question.value = "Answer 2"}} 

你可以請看看,並檢查我做錯了什麼,並糾正我的代碼。我不是一個高結束PowerShell的傢伙:(

回答

0

你應該設法讓元素,以確保數據已完全加載(略低於$ ie.Navigate)之前加入這一行:

while($ie.ReadyState -ne 4) {start-sleep -m 100} 
+0

這是我工作的:'while($ ie.Busy){start-sleep -m 100}' – bnu 2015-06-26 09:28:18