0

I have a automated IE script (powershell 2.0) to webscrape a serial number. The script bypasses a login page, and scrapes a serial number off a certain page.

However i am having issues in write-output said serial number on the first run of my script. (when i run the script the second time (with the previous ieObject visible), it remembers the login and outputs the correct serial number.

$element = $currentDocument.IHTMLDocument3_getElementById("serialno")| Select innerHTML
write-output "StartScript"
Start-Sleep -s 3
$ieObject | Invoke-IEWait
write-output $element
write-output "EndScript"

i have used debug mode on the script, and $element contains the correct information at the end of the script (i put a breakpoint on write-output "End")debug however it outputs

StartScript

EndScript

Another issue is that if i run the script again, while the original ieObject is still open, the second script remembers the password and actually scrapes correctly?

StartScript

innerHTML                                                                                                                                                                                                                                                          
---------                                                                                                                                                                                                                                                          
2390                                                                                                                                                                                                                                                               
EndScript

I do not see how my first script can be bugged, when $element has the correct data up until the end of the script, and write-output can clearly read the object since it can do it in the second execution.

Thanks for any help, this has had me stuck for a while

mklement0
  • 382,024
  • 64
  • 607
  • 775
Joshfromnz
  • 45
  • 4
  • 1
    Apperarently, (from the debug information), `$element` is an object. Try: `write-output $element.innerHTML` – iRon Jan 28 '20 at 07:00

1 Answers1

0

Big thanks to @iRon

write-output $element.innerHTML

works perfectly :)

Joshfromnz
  • 45
  • 4