Selenium+java the problem of multi-level frame switching

Source: Internet
Author: User
Tags tagname xpath

About the selenium multi-layer iframe switchover, and the problem of the IFRAME switching without the ID and name attribute. (e.g.:)

Problem:

1. After cut into the frame:left, directly switch other sibling and parent frame error

2. After you cut into Frame:left, and then switch to the frame:index below it, you cannot directly locate the div you want to get

Cause Analysis:

Issue 1: After plunge into Frame:left, to switch to the left sibling Frame:index, you need to first cut back to the initial state defaultcontent. Then switch to the inner frame again.

Issue 2: After plunge into the inner layer of the frame:index, found that there is an IFRAME without a name and ID, you need to switch to the IFRAME before you can locate the required div

The code is as follows:

  

1  Public classTestframe {2   3     PrivateWebdriver Driver; 4     PrivateString BaseUrl; 5     Privatewebdriverwait wait; 6   7 @Before8      Public voidsetUp () {9Driver =NewFirefoxdriver (); TenBASEURL = "Http://XXXX";  Onewait =NewWebdriverwait (Driver, 5);  ADriver.manage (). Timeouts (). implicitlywait (5, Timeunit.seconds);  -     }   -    the @Test -      Public voidTestframe ()throwsinterruptedexception { - Driver.get (BASEURL);  -Wait.until (NewExpectedcondition<webelement>() {   +    - @Override +              Publicwebelement Apply (webdriver d) { A                 //TODO auto-generated Method Stub at                 returnD.findelement (By.tagname ("Frame"));  -             }   -    -         });  -Driver.switchto (). FRAME ("index");  -Driver.switchto (). FRAME ("Mainindex");  inDriver.switchto (). FRAME ("left");  -Driver.findelement (By.xpath ("//li[2]/span") . Click ();  toDriver.findelement (By.xpath ("//li[3]/span") . Click ();  +Driver.findelement (By.xpath ("//li[3]/ul/li/a/span") . Click ();  - Driver.switchto (). Defaultcontent ();  theDriver.switchto (). FRAME ("index");  *Driver.switchto (). FRAME ("Mainindex");  $Driver.switchto (). FRAME ("index"); Panax NotoginsengDriver.switchto (). FRAME (Driver.findelement (By.tagname ("iframe"))));  -Driver.findelement (By.xpath ("/html/body/div/div"));  the     }   +    A @After the      Public voidTearDown () { + Driver.quit ();  -     }   $}

Selenium+java the problem of multi-level frame switching

Related Article

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.