无法迭代对象

时间:2018-02-01 18:53:07

标签: powershell internet-explorer automation

我在网页上有一个按钮列表。我可以使用Get Class Name函数获取按钮列表。但我无法迭代它。

以下是代码:

<main role="main">
        <div class="wrapper">

        </div>

        <div class="wrapper wrapper-medium">


  <header>
    <h1>Unsubmitted Timesheets</h1>

    <div class="clearfix">
      <div class="fl-left">
        <select name="" id="select-timeframe" class="hui-input"><option value="/missing_time/period/36/2018">05 Feb 2018 - 11 Feb 2018</option>
<option selected="selected" value="/missing_time/period/29/2018">This Week</option>
<option value="/missing_time/period/22/2018">22 Jan 2018 - 28 Jan 2018</option>
<option value="/missing_time/period/15/2018">15 Jan 2018 - 21 Jan 2018</option>
<option value="/missing_time/period/8/2018">08 Jan 2018 - 14 Jan 2018</option>
<option value="/missing_time/period/29/2018?all_weeks=1">- show all weeks -</option></select>
      </div>

        <div class="fl-right">
          <button type="button" class="hui-button" data-open-dialog="email-reminder-dialog">
              <i data-icon="check-green"></i>
              Sending Reminder Every Friday
          </button>
        </div>
    </div>
  </header>

  <section>
      <form id="missing-time-form" action="/missing_time/reminders?return_to=%2Fmissing_time%2Fperiod%2F29%2F2018" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="?"><input type="hidden" name="authenticity_token" value="YmA26BT5bHy1NQKiKks+j/nKl5saFnF2fAmp/Oy6zuWANPkuuMLYTZDtdZHa/7TNh2CcUx5R2e0FsPWOxThVoQ==">
        <table id="unsubmitted-timesheets" class="table">
          <thead>
            <tr>
              <th></th>
              <th>
                Team Members<br>
                <small>
                  Select:
                  <button type="button" class="button-link js-toggle-all-users">All</button>
                  /
                  <button type="button" class="button-link js-toggle-no-users">None</button>
                </small>
              </th>
              <th class="text-right">Time</th>
              <th></th>
            </tr>
          </thead>
          <tbody class="has-clickable-table-rows" data-required-checkboxes="You must select at least one recipient.">
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1964976]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Alexander Cubillos" type="checkbox" value="1" name="send_reminder[1964976]" id="send_reminder_1964976">
                    <label for="send_reminder_1964976"></label>
                  </div>
                </td>
                <td>
                  Alexander Cubillos
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1964976" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  24:00
                  <label for="send_reminder_1964976" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1964976">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1840318]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Allain Dollete" type="checkbox" value="1" name="send_reminder[1840318]" id="send_reminder_1840318">
                    <label for="send_reminder_1840318"></label>
                  </div>
                </td>
                <td>
                  Allain Dollete
                  <label for="send_reminder_1840318" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  24:30
                  <label for="send_reminder_1840318" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1840318">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1882520]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Anil Khemchandani" type="checkbox" value="1" name="send_reminder[1882520]" id="send_reminder_1882520">
                    <label for="send_reminder_1882520"></label>
                  </div>
                </td>
                <td>
                  Anil Khemchandani
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1882520" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1882520" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1882520">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1028098]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Anna Jhaveri" type="checkbox" value="1" name="send_reminder[1028098]" id="send_reminder_1028098">
                    <label for="send_reminder_1028098"></label>
                  </div>
                </td>
                <td>
                  Anna Jhaveri
                  <label for="send_reminder_1028098" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1028098" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1028098">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1399194]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Chaitanya Potluri" type="checkbox" value="1" name="send_reminder[1399194]" id="send_reminder_1399194">
                    <label for="send_reminder_1399194"></label>
                  </div>
                </td>
                <td>
                  Chaitanya Potluri
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1399194" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  40:00
                  <label for="send_reminder_1399194" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1399194">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1908612]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Daniel Pedraza Mena" type="checkbox" value="1" name="send_reminder[1908612]" id="send_reminder_1908612">
                    <label for="send_reminder_1908612"></label>
                  </div>
                </td>
                <td>
                  Daniel Pedraza Mena
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1908612" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  16:00
                  <label for="send_reminder_1908612" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1908612">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1806244]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Danny Davidson" type="checkbox" value="1" name="send_reminder[1806244]" id="send_reminder_1806244">
                    <label for="send_reminder_1806244"></label>
                  </div>
                </td>
                <td>
                  Danny Davidson
                  <label for="send_reminder_1806244" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  40:00
                  <label for="send_reminder_1806244" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1806244">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1918323]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Debbie Fink" type="checkbox" value="1" name="send_reminder[1918323]" id="send_reminder_1918323">
                    <label for="send_reminder_1918323"></label>
                  </div>
                </td>
                <td>
                  Debbie Fink
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1918323" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1918323" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1918323">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1937598]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Dickson Law" type="checkbox" value="1" name="send_reminder[1937598]" id="send_reminder_1937598">
                    <label for="send_reminder_1937598"></label>
                  </div>
                </td>
                <td>
                  Dickson Law
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1937598" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1937598" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1937598">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1221855]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Divyang Patel" type="checkbox" value="1" name="send_reminder[1221855]" id="send_reminder_1221855">
                    <label for="send_reminder_1221855"></label>
                  </div>
                </td>
                <td>
                  Divyang Patel
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1221855" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1221855" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1221855">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1218884]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Hetal Desai" type="checkbox" value="1" name="send_reminder[1218884]" id="send_reminder_1218884">
                    <label for="send_reminder_1218884"></label>
                  </div>
                </td>
                <td>
                  Hetal Desai
                  <label for="send_reminder_1218884" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1218884" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1218884">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1908572]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Hiren Changela" type="checkbox" value="1" name="send_reminder[1908572]" id="send_reminder_1908572">
                    <label for="send_reminder_1908572"></label>
                  </div>
                </td>
                <td>
                  Hiren Changela
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1908572" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  8:20
                  <label for="send_reminder_1908572" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1908572">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1457227]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Jayson Greenberg" type="checkbox" value="1" name="send_reminder[1457227]" id="send_reminder_1457227">
                    <label for="send_reminder_1457227"></label>
                  </div>
                </td>
                <td>
                  Jayson Greenberg
                  <label for="send_reminder_1457227" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1457227" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1457227">View Timesheet</a>
                </td>
              </tr>
                              <td class="text-right">
                  25:11
                  <label for="send_reminder_1955711" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1955711">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1819930]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Ranga Beeram" type="checkbox" value="1" name="send_reminder[1819930]" id="send_reminder_1819930">
                    <label for="send_reminder_1819930"></label>
                  </div>
                </td>
                <td>
                  Ranga Beeram
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1819930" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1819930" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1819930">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1198081]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Ratnakumar Paleru" type="checkbox" value="1" name="send_reminder[1198081]" id="send_reminder_1198081">
                    <label for="send_reminder_1198081"></label>
                  </div>
                </td>
                <td>
                  Ratnakumar Paleru
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1198081" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  40:00
                  <label for="send_reminder_1198081" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1198081">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1250162]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Ricky Raghavan" type="checkbox" value="1" name="send_reminder[1250162]" id="send_reminder_1250162">
                    <label for="send_reminder_1250162"></label>
                  </div>
                </td>
                <td>
                  Ricky Raghavan
                  <label for="send_reminder_1250162" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  43:01
                  <label for="send_reminder_1250162" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1250162">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1983564]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Robert Pearl" type="checkbox" value="1" name="send_reminder[1983564]" id="send_reminder_1983564">
                    <label for="send_reminder_1983564"></label>
                  </div>
                </td>
                <td>
                  Robert Pearl
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1983564" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1983564" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1983564">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1491814]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Roeleke van Munster" type="checkbox" value="1" name="send_reminder[1491814]" id="send_reminder_1491814">
                    <label for="send_reminder_1491814"></label>
                  </div>
                </td>
                <td>
                  Roeleke van Munster
                    <span class="text-label">Contractor</span>
                  <label for="send_reminder_1491814" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  24:00
                  <label for="send_reminder_1491814" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1491814">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1567062]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Suhil Jisahebwala" type="checkbox" value="1" name="send_reminder[1567062]" id="send_reminder_1567062">
                    <label for="send_reminder_1567062"></label>
                  </div>
                </td>
                <td>
                  Suhil Jisahebwala
                  <label for="send_reminder_1567062" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  34:45
                  <label for="send_reminder_1567062" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1567062">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1938412]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Thomas Daly" type="checkbox" value="1" name="send_reminder[1938412]" id="send_reminder_1938412">
                    <label for="send_reminder_1938412"></label>
                  </div>
                </td>
                <td>
                  Thomas Daly
                  <label for="send_reminder_1938412" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:15
                  <label for="send_reminder_1938412" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1938412">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1042800]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Tosha Mehta" type="checkbox" value="1" name="send_reminder[1042800]" id="send_reminder_1042800">
                    <label for="send_reminder_1042800"></label>
                  </div>
                </td>
                <td>
                  Tosha Mehta
                  <label for="send_reminder_1042800" class="clickable-row-link"></label>
                </td>
                <td class="text-right">
                  0:00
                  <label for="send_reminder_1042800" class="clickable-row-link"></label>
                </td>
                <td class="col-actions">
                  <a class="hui-button hui-button-tiny" href="/entry/show/29/2018?of_user=1042800">View Timesheet</a>
                </td>
              </tr>
              <tr class="clickable-row">
                <td class="col-checkbox">
                  <div class="hui-checkbox">
                    <input name="send_reminder[1330499]" type="hidden" value="0"><input class="checkbox" aria-label="Send Reminder for Ujjaval Bhavsar" type="checkbox" value="1" name="send_reminder[1330499]" id="send_reminder_1330499">
                    <label for="send_reminder_1330499"></label>
                  </div>
                </td>
                <td>

</form>    </div>
  </div>
      </main>

我使用类名“hui-button hui-button-tiny”来定位按钮,这就是我尝试过的:

($ie.Document.GetElementsByClassName("hui-button hui-button-tiny") |
    Select-Object -First 1).Click()

因此,通过上述声明,我可以单击页面的第一个按钮。将“first”替换为“last”将允许我单击页面的最后一个按钮。 但这不完全是我想要的。理想情况下,我希望一次点击一个按钮进入相应的页面,然后返回主页面。从那里转到下一个按钮,重复该过程,直到访问了所有按钮。问题是我无法迭代按钮。这就是我尝试过的:

#$View_Timesheet_Object=$ie.document.getElementsByClassName("hui-button hui-button-tiny")
for ($i=0; $i -le $View_Timesheet_Object.Length; $i++) {
    ($View_Timesheet_Object | Select-Object $i).Click()
    #Perform Actions on the second page
    #Navigate back to the main page
    $ie.Navigate(Main Page)
}

我收到此消息:

Select-Object : Cannot convert System.Int32 to one of the following types
{System.String,  System.Management.Automation.ScriptBlock}.
At C:\Users\rr\Documents\PowerShell\ie6.ps1:37 char:26
+ ($View_Timesheet_Object |Select-Object $i).click()
+                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException
    + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectComm

我尝试通过执行此命令来检查计数

Write-Host $View_Timesheet_Object.Count

但它总是返回0.

0 个答案:

没有答案