Complete the code to switch to the iframe by its name.
driver.switchTo().frame([1]);To switch to an iframe by its name, pass the name as a string to frame().
Complete the code to switch to the iframe by its index.
driver.switchTo().frame([1]);To switch to an iframe by index, pass the zero-based index as an integer.
Fix the error in switching to the iframe using a WebElement.
WebElement iframeElement = driver.findElement(By.id("[1]")); driver.switchTo().frame(iframeElement);
The findElement method locates the iframe by its id. Use the correct id value.
Fill both blanks to switch to an iframe by WebElement and then back to the main page.
WebElement iframe = driver.findElement(By.[1]("frameId")); driver.switchTo().frame(iframe); driver.switchTo().[2]();
name instead of id when locating the iframe.parentFrame() instead of defaultContent() to switch back.Locate the iframe by id and switch back to the main page using defaultContent().
Fill all three blanks to switch to an iframe by name, perform an action, and switch back.
driver.switchTo().frame([1]); WebElement button = driver.findElement(By.id([2])); button.click(); driver.switchTo().[3]();
parentFrame() instead of defaultContent() to switch back.Switch to the iframe by its name "myFrame", find the button by id "submitBtn", click it, then switch back to the main page using defaultContent().