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