Open
Description
Description
When using SafariDriver, if you switch into a dynamically loaded iframe (such as a login modal), and that iframe is then removed from the DOM (e.g., after submitting a login form), and there are no more frames present on the page, all subsequent WebDriver commands (findElement, getPageSource, etc.) throw a NoSuchFrameException.
If you attempt to recover by calling driver.switchTo().defaultContent(), subsequent interactions no longer throw, but instead consistently return null for every command (for example, driver.findElement returns null, driver.getPageSource() returns null, and executing JavaScript returns null).
Reproducible Code
driver.get(url)
driver.switchTo().frame(<my_dynamic_frame>);
//Submit the login so that the iframe is removed from the page.
driver.getPageSource();
//Result: org.openqa.selenium.NoSuchFrameException
driver.switchTo().defaultContent();
driver.getPageSource();
//Result: null
Debugging Logs
Driver info: org.openqa.selenium.safari.SafariDriver
Command: [577D814E-8A32-4640-8445-1BE31A30A571, getPageSource {}]
Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 17.3.1, platformName: MAC, safari:automaticInspection: true, safari:automaticProfiling: false, safari:diagnose: true, safari:platformBuildVersion: 23D60, safari:platformVersion: 14.3.1, safari:useSimulator: false, selenoid:options: {enableVNC: true, enableVideo: false, name:---}, setWindowRect: true, strictFileInteractability: false, webkit:WebRTC: {DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}}
Session ID: 577D814E-8A32-4640-8445-1BE31A30A571