PowerShell - 一个带有多个选项卡的IE浏览器

时间:2015-07-30 14:59:09

标签: javascript internet-explorer powershell browser tabs

凭证变量

$usernameMI = "myusername"
$passwordMI = "mypassword"
$usernameBES = "myusername2"
$passwordBES = "mypassword"
$domainBES = "thedomain"

第一站点

$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate("https://mobility-vsp4.corp.com/mifs/login.jsp")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value= $usernameMI
$ie.document.getElementById("password").value = $passwordMI
$ie.document.getElementById("login-btn").click();

第二站点

$ie = New-Object -com InternetExplorer.Application
$ie.navigate("https://chq-exch-bas01.corp.dsfsd.com/webconsole/app?consoleSId=&page=Login&service=page")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("overridelink").click()
$ie.navigate("https://chq-exch-bas01.corp.sdfsdf.com/webconsole/app?consoleSId=&page=Login&service=page")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.visible = $true
$ie.document.getElementById("text_username").value= $usernameBES
$ie.document.getElementById("text_password").value = $passwordBES
$ie.document.getElementById("text_domain").value = $domainBES
$ie.document.getElementById("loginImage").click()

第三站点

$ie = New-Object -com InternetExplorer.Application
$ie.navigate("https://chq-exch-bdsx.corp.sdfsd.com:38443/webconsole/app?page=ReLogin&service=page")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("loginLink").click()
$ie.navigate("https://chq-exch-bdsx.corp.sdfsdf.com:38443/webconsole/app?consoleSId=&page=Login&service=page")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.visible = $true
$ie.document.getElementById("text_username").value= $usernameBES
$ie.document.getElementById("text_password").value = $passwordBES
$ie.document.getElementById("text_domain").value = $domainBES
$ie.document.getElementById("loginImage").click()

我希望在登录每个网站的同时在一个浏览器中填充所有网站并使用多个标签 - 这可能吗?

  

这是我尝试过的,虽然它仍然没有承认网站2和3。它留下2和2。 3在登录页面。

$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("https://mobility-vsp1.dsdfss.com/mifs/login.jsp");
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value= $usernameMI
$ie.document.getElementById("password").value = $passwordMI
$ie.document.getElementById("login-btn").click();

while($ie.busy -eq $ture) 
{
start-sleep -milliseconds 10000;
}

$ie.Navigate2("https://chq-exch-bas01.corp.sdfsd.com/webconsole/app?consoleSId=&page=Login&service=page", $navOpenInBackgroundTab);
$ie.document.getElementById("overridelink").click()
$ie.document.getElementById("text_username").value= $usernameBES
$ie.document.getElementById("text_password").value = $passwordBES
$ie.document.getElementById("text_domain").value = $domainBES
$ie.document.getElementById("loginImage").click()

while($ie.busy -eq $ture) 
{
start-sleep -milliseconds 10000;
}

$ie.Navigate2("https://chq-exch-bdsx.corp.sdfsdf.com:38443/webconsole/app?page=ReLogin&service=page", $navOpenInBackgroundTab);
$ie.document.getElementById("loginLink").click()
$ie.document.getElementById("text_username").value= $usernameBES
$ie.document.getElementById("text_password").value = $passwordBES
$ie.document.getElementById("text_domain").value = $domainBES
$ie.document.getElementById("loginImage").click()

$ie.visible = $true 

2 个答案:

答案 0 :(得分:0)

这样我就可以在一个IE中打开多个标签

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.Navigate("http://www.microsoft.com")
$ie.Navigate2("http://www.google.com" , 2048)
$ie.Navigate2("http://www.outlook.com" , 2048)
$ie.Visible = $true

在调用下一个代码之前将代码添加到页面中并且应该可以正常工作。

答案 1 :(得分:0)

我知道我正在回答一个将近四年的问题,但是在尝试访问多个选项卡上的JavaScript变量时遇到了类似的问题。我最终要做的是创建一个外壳应用程序COM对象,使用该对象访问并将每个选项卡存储在其自己的变量中,然后使用IHTMLDocument3_getElementByID()访问每个选项卡的DOM。由于某些原因,当您有多个标签时,普通的getElementByID()方法不起作用。

代码看起来像这样:

$sa = New-Object -com Shell.Application
$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("https://mobility-vsp1.dsdfss.com/mifs/login.jsp");
while($ie.ReadyState -ne 4) {start-sleep -m 100}
#the full URL doesn't have to be entered to return a match in the code below
$tab1 = $sa.Windows() | Where-Object {$_.locationURL -match "mobility-vps1.dsdfss.com"} 
$tab1.document.IHTMLDocument3_getElementById("username").value= $usernameMI
$tab1.document.IHTMLDocument3_getElementById("password").value = $passwordMI
$tab1.document.IHTMLDocument3_getElementById("login-btn").click();

while($ie.busy -eq $true) 
{
start-sleep -milliseconds 10000;
}

$ie.Navigate2("https://chq-exch-bas01.corp.sdfsd.com/webconsole/app?consoleSId=&page=Login&service=page", $navOpenInBackgroundTab);
$tab2 = $sa.Windows() | Where-Object {$_.locationURL -match "chq-exch-bas01.corp.sdfsd.com"}
$tab2.document.IHTMLDocument3_getElementById("overridelink").click()
$tab2.document.IHTMLDocument3_getElementById("text_username").value= $usernameBES
$tab2.document.IHTMLDocument3_getElementById("text_password").value = $passwordBES
$tab2.document.IHTMLDocument3_getElementById("text_domain").value = $domainBES
$tab2.document.IHTMLDocument3_getElementById("loginImage").click()

while($ie.busy -eq $true) 
{
start-sleep -milliseconds 10000;
}

$ie.Navigate2("https://chq-exch-bdsx.corp.sdfsdf.com:38443/webconsole/app?page=ReLogin&service=page", $navOpenInBackgroundTab);
$tab3 = $sa.Windows() | Where-Object {$_.locationURL -match "chq-exch-bdsx.corp.sdfsdf.com"}
$tab3.document.IHTMLDocument3_getElementById("loginLink").click()
$tab3.document.IHTMLDocument3_getElementById("text_username").value= $usernameBES
$tab3.document.IHTMLDocument3_getElementById("text_password").value = $passwordBES
$tab3.document.IHTMLDocument3_getElementById("text_domain").value = $domainBES
$tab3.document.IHTMLDocument3_getElementById("loginImage").click()

$ie.visible = $true