0

I am trying to automate the IE link where I am logging into the webpage and selecting some dropdown option on that. I am able to login to the link but not able to select the option from dropdown.

while ($ie.Busy -eq $true -or $ie.Document -eq $null ){Start-Sleep -seconds 1;} 

$dropDown = $ie.Document.getElementById("state-area").contentDocument.getElementById("state-status")[1].selected = $true

Write-Host("Trying to select the dropdown")

$dropDown = $ie.Document.getElementById("state-area").contentDocument.getElementById("state-status").FireEvent("Ready")

Output:

You cannot call a method on a null-valued expression.
At C:\Documents\TestScript4.ps1:51 char:13
+ $dropDown = $ie.Document.getElementById("state-area").contentDocument.getElement ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Trying to select the dropdown

You cannot call a method on a null-valued expression.
At C:\Documents\TestScript4.ps1:59 char:1
+ $dropDown = $ie.Document.getElementById("state-area").contentDocument.getElement ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
CL.
  • 173,858
  • 17
  • 217
  • 259
Vidya M
  • 1
  • 1
  • Two things. Firstly, you can try breaking down your `$dropDown` assignment into steps, which will help to isolate the problem. Secondly, you may be running into an Internet Explorer security feature, whereby it spawns child processes for loaded pages. IIRC, this makes the DOM inaccessible, depending on your Windows version. – andyb Sep 06 '17 at 02:40
  • See https://stackoverflow.com/questions/27299167/internetexplorer-application-document-getelementbyid-returns-as-null-powershel and https://stackoverflow.com/questions/13869518/powershell-ie9-comobject-has-all-null-properties-after-navigating-to-webpage/14996243#14996243 – andyb Sep 06 '17 at 02:50
  • To format code, select the entire block and click the `{}` button in the toolbar (or press Ctrl+K). – Cody Gray - on strike Sep 06 '17 at 03:38

0 Answers0