Powershell - Beginner Advice for looping through an array -
I am using PowerShell to do some high level automation and I loop through an array of 2 values Want a dropdown list on a website ... there is no way how to implement it.
Here is the code:
$ Array = "FirstItem", "second Itam", Foreach $ I $ Array) {while ($ ie.busy) {sleep 1} $ Doc = $ ie.document $ ie.document.getElementById ("DropDownListBtn"). Click () $ link = $ ie.Document.getElementsByTagName ('A') | Where-object {$ _. InnerText-eq '$ i'} # Note: Without using the above variable, I hope the statement will look like this: # $ link = $ ie.Document.getElementsByTagName ('A') | Where the object {$ _ InnerText-eq 'FirstItem'} $ link.click ()} Here is an error: You can not call on a null-valuable expression In the method line: 9 char: 28 + $ link.click & lt; & Lt; & Lt; & Lt; () + Category information: Invalid operation: (click: string) [], runtime expansions + fully qualified error: invokyoutional
You need some error handling / checking
I'm starting to deal with an error in my current $ and $ link instantaneous code like:
$ ie = & lt; Code to create an object & gt; Terrorism released quietly; If ($?) {# OK - go ahead} and {# it failed}
... or try ... hold, but it does not always work Not all PowerShell calls allow exceptions to be lifted.
Try {$ ie = & lt; To create code object & gt; Terrorism released quietly; } Hold [exception] {# it fails}
Comments
Post a Comment