Turn from: http://www.webdriver.org/article-32-1.html
During the testing process, we often encounter many pop-up boxes to deal with, such as login username password input, or page warning, or a new page pop-up, this article we will take these categories, and explain how to handle different pop-up boxes.
Normal pop-up Div
Generally this pop-up is part of the DOM, we look at the page source can be positioned to change the pop-up box, and then locate the upper right corner of the closed, here is the ID, so very convenient through
Dr.findelement (by.id ("xxx")). Click (); You can turn off this pop-up box.
2, New Window pop-up box
Here we can see a new browser window that pops up after clicking the Open New Window link.
At this point, we need to use the switch window method, generally for two windows, we can directly switch to a non-current window on it, the code is as follows:
Set handles = Dr.getwindowhandles ();
String Currenthandle = Dr.getwindowhandle ();
for (String handle:handles)
{
if (!handle.equals (Currenthandle))
{
Dr.switchto (). window (handle);
Break
}
}
If the window is more, we need to use other methods, such as the title of the window, or the URL of the new window to determine the window we need to switch.
3, Alert pop-up box
Finally, let's introduce some alert pop-up boxes,
1). Alert Type:
Click OK
Dr.switchto (). alert (). Accept ();
2). Confirm Type:
Click OK
Dr.switchto (). alert (). Accept ();
Click Cancel
Dr.switchto (). alert (). dismiss ();