seleniumselenium-webdriverremotewebdriver

GetTitle() Method of WebDriver is not working for Frame Tag Doc


I am trying to fetch of Frame after switching but it is still returning Title of Main WebPage. Sharing code and DOM details of Frame:

    WebDriver driver  = new ChromeDriver();

    driver.get("http://www.dwuser.com/education/content/the-magical-iframe-tag-an-introduction/");

    List<WebElement> IframaList=driver.findElements(By.tagName("iframe"));

    System.out.println("total number of frame is "+IframaList.size());

    for(WebElement e : IframaList){
        System.out.println( e.getAttribute("name"));
    }

    driver.switchTo().frame("myDemoFrame");

    

    System.out.println(driver.getTitle());

Dom Structure :

Dom Details with Title ttag

Note: I checked RemoteWebdriver Implementation of gettitle() and It says that It returns the title of Page. Does it mean the Title of the WebPage only?


Solution

  • The function getTitle() only returns the top level Title

    Refer to the document below for more info.

    This command returns the document title of the current top-level browsing context, equivalent to calling document.title.

    https://www.w3.org/TR/webdriver1/#get-title