2013-02-11 84 views
5

Web驱动程序中是否有任何方法可用于获取页面中的所有框架。就像我们有获取所有窗口句柄的方法。如何获取页面中的框架名称

driver.getWindowHandles() 
+0

你能澄清你的问题吗? – aimbire 2013-02-11 12:52:41

回答

6

这也许是你想要什么,然后:

public void getIframe(final WebDriver driver, final String id) { 
    final List<WebElement> iframes = driver.findElements(By.tagName("iframe")); 
    for (WebElement iframe : iframes) { 
     if (iframe.getAttribute("id").equals(id)) { 
     // TODO your stuff. 
     } 
    } 
} 

然而重要的是要提醒的是,如果你的页面有太多的这些对象,代码可能会变慢一点,但即时通讯在使用此解决方案时在我的测试中谈论了超过100多个。

2

试试这个代码:

//Assume driver is initialized properly. 
    List<WebElement> ele = driver.findElements(By.tagName("frame")); 
    System.out.println("Number of frames in a page :" + ele.size()); 
    for(WebElement el : ele){ 
     //Returns the Id of a frame. 
     System.out.println("Frame Id :" + el.getAttribute("id")); 
     //Returns the Name of a frame. 
     System.out.println("Frame name :" + el.getAttribute("name")); 
    } 
+0

不能暗含转换 – Lijo 2016-07-13 11:44:32