使用powershell从新窗口读取文本
我正在尝试制作一个powershell脚本,它将从javascript链接打开一个新的IE窗口,我想从这个新窗口读取一个文本。到目前为止,脚本只读取原始IE窗口中的内容,我不知道如何让脚本读取新IE页面中的内容使用powershell从新窗口读取文本,powershell,Powershell,我正在尝试制作一个powershell脚本,它将从javascript链接打开一个新的IE窗口,我想从这个新窗口读取一个文本。到目前为止,脚本只读取原始IE窗口中的内容,我不知道如何让脚本读取新IE页面中的内容 $ie = new-object -com InternetExplorer.Application $ie.navigate("https://www.testsite.com/") do {sleep 1} until (-not ($ie.Busy)
$ie = new-object -com InternetExplorer.Application
$ie.navigate("https://www.testsite.com/")
do {sleep 1} until (-not ($ie.Busy))
$ie.visible = $true
$doc = $ie.document
if ($ie.document.documentelement.innerText.Contains('Welcome') -eq "True") {
"Site is RUNNING"
} else {
"Site is STOPPED"
}
$link = @($ie.Document.getElementsByTagName('A')) | Where-Object {$_.innerText -eq 'Click here for new site'}
$link.click()
if ($ie.document.documentelement.innerText.Contains('New Page') -eq "True") {
"Site is RUNNING"
} else {
"Site is STOPPED"
}
$link.click()之后会弹出新窗口,我不知道如何从新窗口读取任何内容。我可以从原来的www.test.com/页面上阅读文本,但不能从新页面上阅读
多谢各位
PT您可以使用以下代码迭代所有IE窗口/选项卡,并选择一个标题为您要查找的窗口/选项卡:
$title = '...'
$ie2 = (New-Object -COM 'Shell.Application').Windows() | ? {
$_.Name -eq 'Windows Internet Explorer' -and $_.LocationName -eq $title
}
谢谢您。我能够使用相同的概念创建单独的shell.application并从该窗口获取输出。