Я написал сценарий powershell для автоматического входа на веб-сайт.Работает нормально.Я хотел бы расширить сценарий для открытия другого сайта в новой вкладке и автоматически войти в систему. Я могу открыть вторую вкладку без проблем, но код для передачи учетных данных выполняется на первой вкладке вместовторая вкладка.Чтобы убедиться в этом, я быстро нажал кнопку «Назад» на первой вкладке, чтобы вернуться к экрану входа в систему, прежде чем открылась вторая вкладка, и наблюдал, как, хотя вторая вкладка была первой, сценарий пытался войти в систему.Первая открытая вкладка.Как я могу гарантировать, что код скрипта взаимодействует со следующей открытой вкладкой вместо первой открытой вкладки.Полный код, который я использую ниже.Спасибо за внимание.
#Create an IE object
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible = $true
#Open the site
$ie.Navigate("www.mysite.com")
#Pauses the script to wait for the site to load
while($ie.Busy -eq $true){Start-Sleep -seconds 3;}
#Feeds the credentials to the form
#Note: you will need to view the source code of your site to get the correct element IDs
$usernamefield = $ie.Document.getElementByID('username')
$usernamefield.value = 'myuser'
$passwordfield = $ie.Document.getElementByID('password')
$passwordfield.value = 'mypassword'
while($ie.Busy -eq $true){Start-Sleep -seconds 2;}
$submitButton = $ie.document.getElementByID('loginbutton').click()
#######################################################################################################
while($ie.Busy -eq $true){Start-Sleep -seconds 5;}
#Open site 2
$ie.Navigate2("www.myothersite.com", 2048)
$ie.Visible = $true
#Pauses the script to wait for the site to load
while($ie.Busy -eq $true){Start-Sleep -seconds 3;}
#Feeds the credentials to the form
#Note: you will need to view the source code of your site to get the correct element IDs
$usernamefield = $ie.Document.getElementByID('username')
$usernamefield.value = 'myuser'
$passwordfield = $ie.Document.getElementByID('password')
$passwordfield.value = 'mypassword'
while($ie.Busy -eq $true){Start-Sleep -seconds 2;}
$submitButton = $ie.document.getElementByID('loginbutton').click()