Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to switch to the iframe using its name.
Selenium Python
driver.switch_to.[1]('frameName')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
window instead of frame causes errors.Trying to switch to
alert when dealing with iframes.✗ Incorrect
Use switch_to.frame() to switch to an iframe by name or ID.
2fill in blank
mediumComplete the code to switch back to the main page from an iframe.
Selenium Python
driver.switch_to.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
frame to switch back causes staying inside the iframe.Using
window is incorrect for iframe switching.✗ Incorrect
Use switch_to.default_content() to return to the main page from any iframe.
3fill in blank
hardFix the error in switching to an iframe using a WebElement.
Selenium Python
iframe_element = driver.find_element(By.ID, 'frameId') driver.switch_to.[1](iframe_element)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
window or alert causes errors.Trying to switch to
default_content when inside iframe.✗ Incorrect
Use switch_to.frame() with a WebElement to switch to that iframe.
4fill in blank
hardFill both blanks to switch to an iframe by index and then back to the main page.
Selenium Python
driver.switch_to.[1](0) # do something inside iframe driver.switch_to.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
parent_frame instead of default_content to return.Using
window causes errors.✗ Incorrect
Use frame(0) to switch by index and default_content() to return.
5fill in blank
hardFill all three blanks to find an iframe by CSS selector, switch to it, and then switch back.
Selenium Python
iframe = driver.find_element(By.[1], '[2]') driver.switch_to.[3](iframe) # interact inside iframe driver.switch_to.default_content()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
xpath with a CSS selector string causes errors.Using
default_content to switch to iframe is wrong.✗ Incorrect
Find iframe by CSS selector #myFrame, switch using frame().