Various types of Selenium webdriver pop-up boxes _selenium

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.