Switch to frame Select a frame by its (zero-based) index driver.switchTo().frame(int index) Select a frame by its name or ID driver.switchTo().frame(String nameOrId) Select a frame by WebElement driver.switchTo().frame(WebElement frameElement) Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged driver.switchTo().parentFrame(); Selects either the first frame on the page, or the main document when a page contains iframes driver.
During script development or debugging in selenium, if we can attach the code to an existing browser session, it will make things easier. Here is how to do it with Chrome. Open chrome with remote debugging port "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 Start chrome driver WebDriver wdriver =null; ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222"); driver = new ChromeDriver(options);
In Selenium, there are multiple locator functions, such as By.CssSelector By.XPath By.Id By.Name …… In my case, I would like to use different format, which I can call one method instead of so many, it would be easier to store the locator information somewhere else. The locator format would be ByMethod = selector to Find, for example: css=input[value=’clear’][type=button] So an extension method was created for this, here is the code snippet.