Selenium study notes, selenium

Source: Internet
Author: User

Selenium study notes, selenium

1. I encountered a strange problem today. iframe has two identical IDS (for example)

Use driver. switchTo (). frame ("frmLinkPage1"); this cannot be used.

Later, you can use driver. switchTo (). frame (0 );.

By the way, exit ifrmae.

Driver. switchTo (). defaultContent ();

2. Click a button to open a new window. After processing, close the new window and process the original window. The Code required for this process is as follows.

String detail?whandle = null;

First:

// Obtain the header information of the Main Window
String maindomainwhandle = driver. getdomainwhandle ();

// Obtain the focus switching window of the new window
Set <String> handles = driver. getWindowHandles ();
System. out. println (handles );
Iterator <String> itWin = handles. iterator ();
While (itWin. hasNext ()){
String key = itWin. next ();
If (main1_whandle. equals (key )){
Continue;
}
Detail?whandle = key;

}

// Switch to the new window to get the focus
WebDriver detailWindow = driver. switchTo (). window (detail?whandle );

 

In the next step,

// Close the new window

DetailWindow. close ();
Handles. remove (detail?whandle );
// Switch back to the main window, and return the focus to the main window again
Driver = driver. switchTo (). window (main1_whandle );

 

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.