Background and problems
Someone wrote a Web application that uses the ASP.net forms technology. It uses a DropDownList control, the user selects an item, the page will return, and then the next dynamic display another control, logic is very simple.
This is the generated part of the HTML source code:
<select name= "Eventtypedropdown" id= eventtypedropdown "onchange=" javascript:settimeout (' __doPostBack ' Eventtypedropdown\ ', \ ' \ ') ', 0 ' >
<option value= "Exception" selected= "selected" >Exception</option>
<option value= "Memory" >Memory</option>
<option value= "Perf" >Perf</option>
</select>
Luckily, the control has an ID. The PowerShell script I wrote is as follows:
$ie = new-object-com "Internetexplorer.application"
$eventType = $ie. document.getElementById (' Eventtypedropdown ')
$eventType. selectedindex=1
After the script runs, the down list on the page selects memory, but the following dynamic controls are not displayed because the page does not return.
Tangled up in me all afternoon. Please don't tell me this time, I can use other test framework, test tools. Here, do not want to introduce other tall things, just want to use IE itself to solve this problem.
Solution
I subconsciously open the F12 Development Debugging tool, the onchange event JavaScript code copied into the console, run, the page began to refresh, the following dynamic control loaded out. At this time saw a ray of dawn. That is, the question: executing JavaScript in IE ComObject can solve this problem. How do you do that?
$ie. Document.parentWindow.execScript (' javascript:settimeout ' __dopostback (\ ' eventtypedropdown\ ', \ ') ', 0) ', ' "