Multi-layered framework and window for "Selenium theme" element positioning

Source: Internet
Author: User

Knowledge points in this section

    • Multilayer frame or window switch style: Webdrvier.switchto (). Targetlocator
    • Interface Webdriver.targetlocator All Switchable objects

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

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.