Hi,
I am trying to automate the website login and clicking few links after that. Everything looks good until login and first click, but after that i could not find the link control and getting null-valued exception.
In the Home page, i have 3 links. It works for the first link then after that it can’t find the 2nd link and so on.
Sample Code
$username = “xyz”
$password = “pwd”
$url = “http://abc.com/”
Create an Internet Explorer object
$ie = New-Object -ComObject ‘internetExplorer.Application’
$ie.Visible= $true # Make it visible
Open the website
$ie.Navigate($url)
do {sleep 1} until (-not ($ie.Busy))
Assign the DOM to the $doc variable
$doc = $ie.document
Assign Username and Pwd
$usernameField = $doc.getElementById(‘username’)
$usernamefield.value = ‘username’
Start-Sleep 1
$passwordfield = $doc.getElementByID(‘Password’)
$passwordfield.value = ‘password’
Wait for 2 seconds before click on Login button
Start-Sleep 2
Click Login Button
$submitButton = $doc.getElementByID(“Login”)
$submitButton.click();
Start-Sleep 2
$Link1= $doc.getElementByID(“Link1”)
$Link1.click();
while ($ie.Busy -eq $true){Start-Sleep -seconds 4;}
Start-Sleep 10
$Link2= $doc.getElementByID(“Link2”)
$Link2.click();
while ($ie.Busy -eq $true){Start-Sleep -seconds 4;}
Start-Sleep 5
$Link3= $doc.getElementByID(“Link3”)
$Link3.click();
Please let me know where did i make a mistake.
Thanks in Advance
Nagaraju