PowerShell JavaScript Button Click is there any Force Command?
I want to create automated web tests wi开发者_如何转开发th PowerShell. My problem is now that when I click a button with a JavaScript Popup the script hangs at the following line because the event is not finished. The Popup is loaded but the script hangs.
Is there any force command? Because in the next lines I want to use a Commandlet to click the ok button.
$ie.Document.getElementById("ButtonID")|foreach{$_.Click()} #never finished
There are two approaches to this common problem with automated testing in browsers. Your first option is to redefine all javascript functions with your own mock implementation.
window.alert = function(msg) { log_info(msg); }; window.prompt = function(msg) { return fixture(msg); }; window.confirm = function(msg) { return randomBool; };
Modifying these functions (and others like print, etc) before you start your automation will stop the prompts from blocking the process. But you may still have to worry about security alerts and credential dialogs.
So the second approach is to run a monitoring utility that can interact with the windows on the OS level. Take a look at IEUnit - http://code.google.com/p/ieunit/ It uses a custom activex control called Desktoop (mispelled on purpose) that allows interacting with windows and security alerts from the Windows Script Host.
So you could either use the activex object in powershell or follow this reference - http://msdn.microsoft.com/en-us/magazine/cc163301.aspx for ideas on implementing your own desktoop like module using native powershell features
精彩评论