1

I am very new to Powershell and not expert in HTML/JS

I have this table in a webpage, note that it's not the only table on the page nor these are the only A tags - there are many a tags and tables before it.

<table id="row" class="simple">
   <thead>
      <tr>
         <th></th>
         <th class="centerjustify">File Name</th>
         <th class="centerjustify">File ID</th>
         <th class="datetime">Creation Date</th>
         <th class="datetime">Upload Date</th>
         <th class="centerjustify">Processing Status</th>
         <th class="centerjustify">Exceptions</th>
         <th class="centerjustify">Unprocessed Count</th>
         <th class="centerjustify">Discarded Count</th>
         <th class="centerjustify">Rejected Count</th>
         <th class="centerjustify">Void Count</th>
         <th class="centerjustify">PO Total Count</th>
         <th class="centerjustify">PO Total Amount</th>
         <th class="centerjustify">CM Total Count</th>
         <th class="centerjustify">CM Total Amount</th>
         <th class="centerjustify">PO Processed Count</th>
         <th class="centerjustify">PO Processed Amount</th>
         <th class="centerjustify">CM Processed Count</th>
         <th class="centerjustify">CM Processed Amount</th>
         <th class="centerjustify">Counts At Upload</th>
      </tr>
   </thead>
   <tbody>
      <tr class="odd">
         <td><input type="radio" disabled="disabled" name="checkedValue" value="12047" /></td>
         <td class="leftjustify textColorBlack">
            <a href="loadConfirmationDetails.htm?fId=12047">520100000000000_520100000000000_20170327_01.txt</a>
         </td>
         <td class="centerjustify textColorBlack">1</td>
         <td class="datetime textColorBlack">Mar 27, 2017 0:00</td>
         <td class="datetime textColorBlack">Mar 27, 2017 10:33:24 PM +03:00</td>
         <td class="centerjustify textColorBlack">

What I want is to browse automatically to a href="loadConfirmationDetails.htm?fId=12047 but the fId part is dynamic so I can't use this href as static, but the cell location of this href is always the same; the static part of it is href="loadConfirmationDetails.htm?fId

This A tag (that contains the wanted href) is the 105th a on the page, I was thinking if I can use some cellindex in PS but I didn't find anything on it!

I've tried this but didn't work:

$ParsedHTML=(Invoke-WebRequest "https://uat.website.com/xxx/community/loadConfirmations.htm?initial=false&action=search").ParsedHtml | Where-Object {$_.TagName -eq 'a' } | Select-Object InnerHtml -First 105
$ParsedHTML.click()

Probably because this select all 105 first A tag but I want only to click on the 105th.

I wonder also I can use $ie.Document.IHTMLDocument3_getElementById("row") piped with something like get child and where picking its first A tag or something - but I can't figure how.

1 Answers1

0

If you know it's always the 105th "A" Link on the page then you should be able to get it from the .Links property as follows:

$Web = Invoke-WebRequest "https://uat.website.com/xxx/community/loadConfirmations.htm?initial=false&action=search"  
$Link = $Web.Links[104].href

This is 104 because the array starts at 0.

If it's the 105th element (e.g of all HTML elements) on the page then you should be able to access it via:

$Web.AllElements[104]

Also you should beware that the Links collection does not have a "Click" method as you are trying to use, but it seems this is possible via an Internet Explorer COM object as described here:

Click a hyperlink using powershell

FYI I also expanded my answer on your previous question with a couple of other options on how to get to the element on the page that you want: https://stackoverflow.com/a/43057670/2796058

Community
  • 1
  • 1
Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
  • Hi Mark, it is actually the 105th A tag and not the 105th of all elements. I will trying your Link method and let you know. –  Mar 29 '17 at 09:48