How to navigate a subframe inside a frameset using Selenium WebDriver? How to navigate a subframe inside a frameset using Selenium WebDriver? selenium selenium

How to navigate a subframe inside a frameset using Selenium WebDriver?


I agree, you cannot directly switch to a child frame. Also, make sure to switch to the defaultContent (driver.switchTo.defaultContent) every time you want to switch frame. With regard to your example, driver.switchTo().frame("mainFrame.0.child") --- this could also work, but you need to get rid of unnecessary quotation marks.


Find the index of main frame starting from zero then use

driver.switchTo.frame(mainFrameindex);

Then find the index of sub frame in the main frame

driver.switchTo.frame(subFrameIndex);

You cannot directly switch to a child frame without first switching to the parent frame. This is how it works.


Through chaining methods together, once you switchTo().defaultContent, you can create temporary lists of available frames through findElements() by tagName and go to that specific frames' index...

For example

driver.switchTo()defaultContent();driver.switchTo().frame(driver.findElement(By.tagName("frameset")).findElements(By.tagName("frame")).get(2));