Thursday, December 16, 2010

Selenium - Simulate Modal Dialog Pop-Up

Selenium - Simulate Modal Dialog Pop-Up

when user open a Modal dialog pop-up by selecting a link or button, focus on the parent window is lost and user is forced to act on the pop-up window and close it, before proceeding further. User can't even look at page view source during modal pop-up on the screen.

Selenium work by executing the JavaScript, when pop-up is displayed, parent window JavaScript execution capability is lost, naturally Selenium can't work.

What are the issues I came across?
1. I am not able to open the Modal Pop-Up using selenium, when I select the link I am getting error message, it work fine when I open the window manually with out Selenium. My Modal pop-Up contain complex Ajax functionality that is conflicting with the Selenium Core when I select the pop-up link.
Attaching error screen shot for more clarity.

2. Values returned by the pop-up are mandate fields, I cant submit the page without these values.

I started searching in Google, but there is no solution. I do not have enough time to debug the selenium core and understand why it is conflicting with the application. Need to some how manage with out opening the pop-up. Then I started looking at the view source and understood the return values of the pop-up.
Attaching screen shot of the call statement to modal pop-up from page view source.


                          
Then I though, why can't I update the values directly in the page DOM, so that it is not even required to open the pop-up. Then I could succeed injecting the values and simulated the modal pop-up dialog.
Attaching the Selenium code
String JS =
               "{" +
               " this.page().findElement('id=ctl00_Cphe_txtSuppName').value='Supplier1';" +
               " this.page().findElement('id=ctl00_Cphe_hdnVendorId').value='1267';" +
               " this.page().findElement('id=ctl00_Cphe_hdnContactId').value='233';" +
               "}"; 
      s.getEval(JS);
I hope this post can help people having issues with modal pop-up.
Enjoy!


No comments:

Post a Comment