So I'm doing a little bit of IE automation in powershell.
Here is my code:
$text = "ctl00`$ContentPlaceHolder1`$Login1`$UserName"
$ie = New-Object -ComObject internetexplorer.application
$ie.visible = $true
$ie.navigate($url);
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}
Write-Host -ForegroundColor Green "Attemptin to login to website."
$ie.Document.getElementById("ctl00`$ContentPlaceHolder1`$Login1`$UserName").value = $username
$ie.Document.getElementById("ctl00`$ContentPlaceHolder1`$Login1`$Password").value = $password
$ie.Document.getElementById("ctl00`$ContentPlaceHolder1`$Login1`$LoginButton").Click()
#while ($ie.Busy -eq $true)
#{
Start-Sleep -Milliseconds 5000;
#}
$ie.Document.getElementById("ctl00`$ContentPlaceHolder1`$txtAgentID").value = "BKR00822"
The issue I'm having is with this line:
$ie.Document.getElementById("ctl00`$ContentPlaceHolder1`$ddlAgentID").value = "BKR00822"
That line is referring to a drop down list.
For some reason it's not accepting any property, nor value, nor selected.
here is the source of the html:
<div id="ctl00_ContentPlaceHolder1_pnlOverrideAgentIDEnter">
<div class="override_agent_text_container">
Please override the Agent ID below to view policies of another agent.
</div>
<table cellpadding="0" cellspacing="0" border="0" class="override_agent_controls_container">
<tr>
<td width="10px">Agent Name:
</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlAgentID" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$ddlAgentID\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_ddlAgentID">
<option selected="selected" value="">[Select...]</option>
<option value="BKR00372">1st National Bank</option>
<option value="BKR00012">21ST CENTURY INSURANCE & REINSURANCE BROKERS LIMITED</option>
<option value="BKR00613">21ST CENTURY INSURANCE & REINSURANCE BROKERS LIMITED</option>
<option value="BKR00824">345-815-2126</option>
<option value="BKR00022">ACE INSURANCE BROKERS LIMITED</option>
<option value="BKR00783">Agostini Insurance Brokers (St. Lucia) Ltd</option>
<option value="BKR00032">AGOSTINI INSURANCE BROKERS LIMITED</option>
<option value="BKR00623">AGOSTINI INSURANCE BROKERS LIMITED</option>
<option value="BKR00633">AGOSTINI INSURANCE BROKERS LIMITED</option>
<option value="BKR00042">AMALGAMATED INSURANCE BROKERS LIMITED</option>
<option value="BKR00643">AMALGAMATED INSURANCE BROKERS LIMITED</option>
This is the error that I am getting. There are about 200 drop down items. The item that I'm looking for is in there, I didn't copy it over:
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Sabrin\Desktop\massy-test-web-prog.ps1:25 char:1
+ $ie.Document.getElementById("ctl00`$ContentPlaceHolder1`$ddlAgentID").value = "1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Thank you for your help!