I am writing an automation with Java and Selenium. This automation needs to use IE (rather than Chrome). This uses popup windows, frames and iframes. On many of the windows, Inspect will not work.
What I am trying to do is, for a page, first dump the source code to a file. Then for each frame and Iframe, switch to that frame or Iframe (and do the same thing). Each frame that has its own frames or iframes I switch to and dump.
My output files will have a prefix (like "bill.html" which will have the main frame. Then, each frame or iframe inside it will have a prefix (frame 0 to bill_0.html, frame 1 to bill_1.html, etc). Nested frames will be like bill_0_1.html, etc.
My method is pretty simple. I have a method called
dumpSourceToFile(WebDriver driver, String File)
my method basically does the following
public void dumpIframes(driver, String pref) {
String file = pref + ".html";
dumpSourceToFile(driver, pref);
List<WebElement> allFrames = new ArrayList<>();
List<WebElement> frames = driver.findElements(By.xpath("//frame"));
allFrames.addAll(frames);
List<WebElement> iFrames = driver.findElements(By.xpath("//frame"));
allFrames.addAll(iFrames);
for (Integer ind = 0; ind < allFrames.size(); ind++) {
String npref = pref + "_" + ind.toString(); // new file name
driver.switchTo().frame(ind);
dumpIframes(driver, npref);
driver.switchTo().defaultContent(); // ready for next one
}
but I am getting stale elements now when trying to switch to a frame. When I originally found just iframes and not frames I don't believe this problem happened.
Anyway, what would be the correct way to do this? I tried using frame names, but not all frames have names wither.