Leo Torres
asked on
Powershell and HTML with IE
Code Below works fine now.
But I need to make a change to the way IE is called. I want IE to close after it test a link and open a whole new instance of IE to do the next test. Now I pass links in a foreach loop and all the links use the same window. I need to open close IE when each link is passed to function below. How would that change the code below.
But I need to make a change to the way IE is called. I want IE to close after it test a link and open a whole new instance of IE to do the next test. Now I pass links in a foreach loop and all the links use the same window. I need to open close IE when each link is passed to function below. How would that change the code below.
<# #>
if (!(Get-Variable ie -Scope global -ea SilentlyContinue) -or !$ie.Document)
{
$global:ie = New-Object -comobject InternetExplorer.Application
}
$ie.visible = $true
$ie.silent = $true
$global:ReportPart = "/interface/folderTree.jsp?rootId=216&expandLevel=1&clearUIPath=true&uiPathLabel=Reports"
# /interface/folderTree.jsp?rootId=216&expandLevel=1&clearUIPath=true&uiPathLabel=My+Reports # sample Akebono Brake Corporation UTA 6.1
function Test-ReportSite ([String] $url, [String] $login, [String] $password)
{
$ie.Navigate2($url)
while ($ie.busy) { Start-Sleep -m 100 }
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'loginField' } | % { $_.value = $login }
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'passwordField' } | % { $_.value = $password }
$ie.Document.getElementsByTagName("input") | ? { $_.name -eq 'password' -and $_.type -eq "password" } | % { $_.value = $password }
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'button' } | % { $_.Click() }
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
$ie.Navigate2($url + $ReportPart)
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
$link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -like '*Overtime Report' } | select -First 1 -expandProperty href
if (!$link)
{
$link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -like '*Count' } | select -First 1 -expandProperty href
}
$ie.Navigate2($link)
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
$ie.Document.getElementsByTagName("button") | ? { $_.innerText -eq 'Go' } | % { $_.Click() }
Start-Sleep 5
<# Error message evaluation ignored ATM
$ie.Document.getElementsByTagName("span") | ft -a classname, tagname, innerText #Gets you error
#>
$RunByTest = $ie.Document.body.tagname -eq 'FRAMESET' -and $ie.Document.body.id -eq 'reportViewerFrame'
if ($RunByTest)
{
$TestValue = 200
}
else
{
$TestValue = -200
}
Write-Host "$URL`: $TestValue"
return $TestValue
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works
There is probably a better way than to close IE, but I cannot see any means to reset it.
ASKER
No Worries Thanks it works for me.
Results oriented person. :)
Results oriented person. :)
ASKER
Thanks Qlemo.