javaseleniumselenium-webdriverselenium-firefoxdriverbrowser-automation

How to get the Title of inner frame in selenium webdriver?


In my program, I am trying to get the Title of the inner frame by switching the driver control to inner frame with the help of getTitle() method. But,it is still return the title of main page. please find the below bit of code I tried with

WebDriver driver = new FirefoxDriver();
driver.get("url");
driver.switchTo().frame("frame name/id");
driver.getTitle();

Is there any way to get the Title of the inner frame in selenium webdriver using Java.


Solution

  • Use Below code to achieve the same

    // before switching frame
    
    driver.getTitle(); 
    //or
    
    driver.find_element_by_tag_name("title").get_attribute("innerHTML")
    

    and after switching frame

    driver.switchTo().frame("frame name/id");
    driver.find_element_by_tag_name("title").get_attribute("innerHTML")
    

    Hope This will help as I'm able to do the same using this code