Powershell; Click on a specific link out of a number of similar links -


every month have dl lot of bills lot of different accounts @ same provider. script log in these accounts , navigate correct site. problem is, there lot of bills dl @ site , want dl recent. first link on site, formatted this:

<div class="datatable-cell datatable-cell--w20">                 <div class="btn btn--secondary">                     <a href="/myaccount/bills/bill_download/stringofcharacters" onclick="track('bill_download',{'prop3':'button:bills','events92':1});">download</a>                 </div>             </div> 

i can't script click link. ideas? i've tried multiple ways link, nothing worked (-eq, -match, -contains etc.) have far:

$username = "username"  $password = "password"  $ie = new-object -com internetexplorer.application  $ie.visible=$true $ie.navigate("https://provider.domain/login")  while($ie.readystate -ne 4) {start-sleep -m 100}  $ie.document.getelementbyid("idtoken1").value= "$username"  $ie.document.getelementbyid("idtoken2").value = "$password"  $loginbtn = $ie.document.getelementbyid("login.submit") $loginbtn.click(); start-sleep 5 $ie.navigate("https://provider.domain/myaccount/bills/")  start-sleep 5 

first, have "a" elements, can this:

$aelements = $ie.document.getelementsbytagname("a") 

there are, sure, many of them. have select right 1 among them. example can see has textcontent "download", use code:

$downloadlink = ($aelements | {$_.textcontent -like "download"}) 

however, if there few links "download" text on them , need first, use following:

$downloadlinks = ($aelements | {$_.textcontent -like "download"}) $downloadlink = $downloadlinks | select-object -first 1 

finally, can

$downloadlink.click() 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -