2

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&nbsp;Name:&nbsp;
                    </td>
                    <td>
                        <select name="ctl00$ContentPlaceHolder1$ddlAgentID" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$ContentPlaceHolder1$ddlAgentID\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_ContentPlaceHolder1_ddlAgentID">
                        <option selected="selected" value="">[Select...]</option>
                        <option value="BKR00372">1st National Bank</option>
                        <option value="BKR00012">21ST CENTURY INSURANCE &amp; REINSURANCE BROKERS LIMITED</option>
                        <option value="BKR00613">21ST CENTURY INSURANCE &amp; 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!

1 Answer 1

1

I think your issue is timing. Had plenty of those in my experience with IE automation.

This code ended up working best for me, when waiting for IE page to be loaded:

While ($ie.ReadyState -ne 4)
{
    write-host "Session State: $($ie.ReadyState)"
    Start-Sleep -Milliseconds 100
}
Start-Sleep -Milliseconds 200 # extra buffer 

$ie.Busy is not reliable.

Also,

To select an item in the drop down list you should probably use the selectedIndex property:

$ie.Document.getElementById("list").selectedIndex = 69 
$ie.Document.getElementById("list").FireEvent("onchange")   
Sign up to request clarification or add additional context in comments.

3 Comments

Nope, still get the same error. Property not found on object
Just out of curiosity, do you get property " selectedIndex" not found?
Just reread your html... The actual ID you looking for is " ctl00_ContentPlaceHolder1_ddlAgentID". What you have at the moment is the object name not ID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.