Webdriver - How to handle IE modal pop-up.
Issue Resolved for IE
Before we start understanding the model-popup, lets understand different pop-ups available on the browser. As per my understanding pop-ups are classified into.
1. HTML pop-up
2. JavaScrip pop-up
3. Win32 pop-up
4. Modal pop-up
5. File upload pop-up
6. File download pop-up
HTML pop-up - These are constructed using HTML, so it can be easily handled by Id or xPath. If you are able to locate the object using IE developer tool bar or Firebug then it is HTML popup.
JavaScrip pop-up - This popup is generated by "alert" statement, it can be handled using Webdriver or Java-script.
Alert Java Doc
Win32 pop-up - This popup is generated by windows, I came came across one popup of this kind. Webdriver can't handle it. Need to relay on Auto it or Java Robot class.
Modal pop-up - This is very specific to IE, Microsoft defined it as
When Windows Internet Explorer opens a window from a modal or modeless HTML dialog box by using the showModalDialog method or by using the showModelessDialog method, Internet Explorer uses Component Object Model (COM) to create a new instance of the window. Typically, the window is opened by using the first instance of an existing Internet Explorer process. When Internet Explorer opens the window in a new process,
all the memory cookies are no longer available, including the session ID. This process is different from the process that Internet Explorer uses to open a new window by using the open method.
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
MSDN blog on Modal dialog
When user select Model popup, parent window is blocked waiting for the return value from the popup window. You will be not able to see the view source of the page, need to close the popup then only the parent window is activated.
How to get object properties of the model-popup? Copy the popup URL and open in a new TAB, then it will display in normal window format, where you can use IE Dev Toolbar or FireBug to capture properties.
Modal window popup activation client code looks like this
var val = window.showModalDialog(url + '?Ids=' + Id, null, 'dialogHeight: 600px; dialogWidth: 850px,dialogTop: 190px; dialogLeft: 120px; edge: Raised; center: Yes;help: No; resizable: No; status: No;');
As per Webdriver team this issue is fixed on IE in 2.16.0, but still it is not working.
Workaround provided in Ruby using Fork, but there is no corresponding Fork command in Java.
As per my understanding, currently there is no solution. Even
AutoIt can't handle popup objects because they belong to HTML not the windows, it can hardly handle the Window title. How to handle? This is blocking my major test cases.
1. Change the Modal popup design.
If you can influence and convince the the team, covert the model-popup into
HTML Modal Popup, so that it can be easily handled in other browsers too.
2. Manipulating the page DOM.
3. Java Robot class
When browser open modal popup opened, focus automatically set on the popup. Now assume you don't have mouse input device, handle the elements using "TAB" "Enter" "Space". Robot class also perform the same events as stated above. Given delay of at-least 500ms in between two events, otherwise there are chances of missing the events.
//To
understand the concept, handle the pop-up without mouse
//Same thing
is performed through robot API
//Text that
need to be typed, character by character
//Issue - If
anyone changes the window focus, keys are lost
Wait(5000); // Wait for
model pop, as Webdriver don't handle need hard stop
int keyInput[] =
{
KeyEvent.VK_S, KeyEvent.VK_E, KeyEvent.VK_L, KeyEvent.VK_E,
KeyEvent.VK_N, KeyEvent.VK_I, KeyEvent.VK_U, KeyEvent.VK_M,
};
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
for (int i = 0; i <
keyInput.length; i++)
{
robot.keyPress(keyInput[i]);
robot.delay(100);
}
robot.delay(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER); // Save Btn
File upload pop-up
If you are using file upload control SendKeys work perfectly fine on IE, else you need to relay on
AutoIT.
File download pop-up
Need to depend on
AutoIt, it works good with windows objects.
---