Knowledge points in this section
Reference Api-interface Webdriver.targetlocator
Webdriver driver= new Firefoxdriver ();//Start Firefox browser
Driver.manage (). window (). Maximize ();
1. Toggle Frame
Driver.switchto (). FRAME (int index); Position frame According to the index number of frame, starting from 0, it can be 0,1,2,....
Driver.switchto (). FRAME (String Nameorid); Locate by frame's name or ID
Driver.switchto (). FRAME (Driver.findelement (by.by)); Positioning attributes according to the elements of a frame
Driver.switchto (). Defaultcontent ();// Switch to open page is focus default frame
2. Toggle Window
Driver.driver.switchTo (). Window (String nameorhandle);//According to the name or handle of window, if the name is known directly input. If no name can be called according to the page title the following methods to switch windows
/*** Toggle page Based on page title *@paramwindowtitle * @boolean switch to the expected page returns true, otherwise false is returned*/ Public Static BooleanSwitchtowin (String windowtitle) {if(Driver.gettitle (). Equals (WindowTitle)) {return true;//if it is the current page, return directly}Else{ for(String handle:driver.getWindowHandles ()) {Driver.switchto (). window (handle); if(Driver.gettitle (). Equals (WindowTitle)) {return true; }Else{ Continue; } } } return false; }
3. Switch to the pop-up window
Driver.switchto (). alert ();//Switch to pop-up window, the next step is to manipulate the alert object
4. Switch to the current frame default focus element
Driver.switchto (). Activeelement ()
Multi-layered framework and window for "Selenium theme" element positioning