Automate IE with Powershell

I am trying to automate the login to a website on our intranet using Powershell and IE. So far I have the following code that works:

$ie = new-object -com "InternetExplorer.Application" 
$ie.navigate("https://somepage/jsp/module/Login.jsp/")
while($ie.ReadyState -ne 4) {start-sleep 1} 
$ie.visible = $true 
$doc = $ie.Document
If ($doc.nameProp -eq "Certificate Error: Navigation Blocked") {
    $doc.getElementByID("overridelink").Click()
}
$loginid = $doc.getElementById("loginid") 
$loginid.value= "username"
$password = $doc.getElementById("password")
$password.value = 'somepass'
$ie.navigate("javascript:doSubmit('login')",$null,$true)

So, the problem that I am facing right now is that the site closes the original window used for logging in and opens a new IE window. How can I imagine input to this new window? I know that I can use something like tasklist.exe / v to get the PID of a new window ... but I'm not sure how I would take control of this.

Also, after looking at my code, please know that I do not intend to use the built-in username and passwords. This is only in place, so I don’t need to constantly enter un / pw compilation every time I want to test a script.

+4
3

...

$applist = new-object -com shell.application
$newie = $applist.windows() | where {$_.Type  -eq "HTML Document" -and $_.LocationURL -match "MainFrame.jsp"}
+2

, , , , Shell.Application. , , , , , .

, Selenium Webdriver. Internet Explorer, # PowerShell. , - , /. driver.switchTo(), .

+2

.

  • $shell = (New-Object -ComObject Shell.Application).Windows()
  • $shell.Count
  • 7
  • 0-6, .
  • $shell.Item(0).LocationName
  • $shell.Item(0).LocationURL
  • $ shell.Item (1) .LocationName
  • $ shell.Item (1) .LocationURL
0
source

Source: https://habr.com/ru/post/1542556/


All Articles