Ok so I recently learned how to execute UI automation using the $ie = new-object -com "internetexplorer.application" command. This works pretty good for a task I am attempting to automate on an ASPX web app...until I ran into a modal popup which freezes my script. From what I have read online, I may want to bypass this by running this same process on a form, using a forms.webbrowser control.Sample Follows
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$form = New-Object Windows.Forms.Form
$form.text = "My Form"
$form.size = New-Object Drawing.size @(700,600)
$web = New-object System.Windows.Forms.webbrowser
$web.location = New-object System.Drawing.Point(3,3)
$web.minimumsize = new-object System.Drawing.Size(20,20)
$web.size = New-object System.Drawing.size(780,530)
$web.navigate("http://myASPXsite.com")
$form.Controls.Add($web)
$form.showdialog()
$doc = $web.document
$doc.getElementbyID('txtUserName').value = "myUser"
The point is that the ability to reference and invoke html elements doesn't work through this method. I can navigate to the webpage but nothing more. Could it be that the webbrowser control doesn't have the same functionality as the internetexplorer object. This is the code I would use with the other method.
$ie = new-object -com "internetexplorer.application"
$ie.navigate("http://www.MyASPXsite.com")
While ($ie.readystate -ne 4) {start-sleep -m 100}
$doc = $ie.document
$doc.getelementbyid('txtUserName').value = "myUser"
Any ideas on my situation? Am I even on the right track to handle the modal dialogs?
Your problem is $form.showdialog(). The script will hold up in this point until you close the form. You have to add an event handler to the form's Shown event something like this:
$form.Add_Shown({
$doc = $web.document;
$doc.getElementbyID('txtUserName').value = "myUser";
});
Then it should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With