Java Selenium processing element examples in an IFRAME _java

Source: Internet
Author: User

Java Selenium processing elements in an IFRAME

Sometimes when we locate elements, we find that we cannot locate them. You need to check to see if the element you're targeting is in the IFRAME.

Reading Table of Contents

What is an IFRAME?

An IFRAME is HTML, used for Web page nesting. A Web page can be nested into another page and can be nested in many layers.

Selenium provides a way to enter the IFRAME

Enter the IFRAME Dr.switchto () with ID called Framea
(). FRAME ("Framea");

Return to the main window
Dr.switchto (). Defaultcontent ();
 

Main.html

 
 

Frame.html

 
 

Selenium code

public static void Testiframe (Webdriver driver)
  {
    driver.get ("E:\\stashfolder\\huoli_28@hotmail.com\\stash \\Tank-MoneyProject\\ Pudong Software Park training center \ My textbook \\Selenium webdriver\\frame\\main.html ");  
    
    In the main window
    driver.findelement (by.id ("Maininput")). SendKeys ("main input");
    At this time did not enter the IFRAME, the following statement will error
    //driver.findelement (by.id ("Iframeinput")). SendKeys ("iframe input");
        
    Driver.switchto (). FRAME ("Framea");
    Driver.findelement (By.id ("Iframeinput")). SendKeys ("iframe input");
    
    There is no main window, the following statement will error
    //driver.findelement (by.id ("Maininput")). SendKeys ("main input");
    
    Return to the main window
    Driver.switchto (). Defaultcontent ();
    Driver.findelement (By.id ("Maininput")). SendKeys ("main input"); 
  }

The above is the Java selenium processing the elements of an IFRAME example, follow-up to continue to collate relevant information, thank you for your support of this site!

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.