简体   繁体   中英

WebDriver > switch between sibling frames

I have the following HTML with frames

<frameset border="0" cols="*,0">
  <frame scrolling="auto" src="/cgi-bin/haipage/page.html?tpl=ntrc/index" name="smgleft">
    <html>
      <head>
    <frameset frameborder="0" border="0" rows="20%,*" cols="100%">
      <frame scrolling="no" marginheight="0" marginwidth="0" src="/cgi-bin/haipage/page.html?tpl=Administration/b" name="head">
      <frame scrolling="auto" marginhei![enter image description here][1]ght="0" marginwidth="0" src="/cgi-bin/haipage/page.html" name="main">
          </html>
          </frame>
        </frameset>
    </html>
  </frame>
</frameset>

When I land on page I'm using

 wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("head"));

Since I want to access some elements under 'head' frame

Now I want to switch frame = main, so I am using

 driver.switchTo().defaultContent();
 driver.switchTo().frame("main");

but I get error message saying 'Unable to find frame'. I believe call to driver.switchTo().defaultContent() get to the top, then go down to the frame you want.

Also, when I try to find the frames after switching to the defaultContent(), I see in the logs only one frame = 'smgleft'

 List<WebElement> frameset = driver.findElements(By.tagName("frame"));  
   if(frameset.size()>0) {  
            for (WebElement framename : frameset)
                logger.info("frameid: " + framename.getAttribute("name"));               
            }

Am I missing something here? How do I switch between sibling frames?

From what I remember, there is no such thing called "switch between sibling frames". What you were doing should be correct in theory (except for if you want to go inside main from default content, you need to switch to smgleft first)

So have you tried

driver.switchTo().defaultContent();
driver.switchTo().frame("smgleft");
// maybe some debugging here see if you can find frame "main" now
driver.switchTo().frame("main");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM