Problem with loading Internet Explorer browser controlled by Powershell

0

I'm trying to make sure that while the browser is ready, it waits for seconds until it is ready and the code is executed but this is skipped and the code is executed when the browser is not ready. How do I prevent this from happening? / p>

 cls
 $ie = New-Object -ComObject InternetExplorer.Application
 $ie.navigate2("https://www.youtube.com")
 $ie.visible = $true
 while($ie.Busy) { Start-Sleep -Milliseconds 100 }    <---no esta funcionando
 $ie.Document.getElementsByTagName("input")[16].outerHTML
 $ie.Quit()
    
asked by ortiga 24.04.2018 в 19:23
source

1 answer

1

You can modify your code block in the following way:

 cls
 $ie = New-Object -ComObject InternetExplorer.Application
 $ie.navigate2("https://www.youtube.com")
 $ie.visible = $true
 while($ie.ReadyState -ne 4) { Start-Sleep -Milliseconds 100 }
 $ie.Document.getElementsByTagName("input")[16].outerHTML
 $ie.Quit()

Moving on to using the ReadyState property (more information in the following link ).

The numeric value 4 indicates that the operation was completed.

    
answered by 24.04.2018 / 21:06
source