selenium “selectframe” command example with relative=up

Last updated on October 8th, 2025 at 11:36 am

“selectframe” Command in selenium 

You need to use “selectframe” command in selenium when your page contains iframe anf you have to perform some action on element inside iframe. You need to provide name or id attribute of iframe element into target column. Here is the simple example of iframe.


Iframe Tutorial



New Test
Command Target Value
click link=AltaVista.com
selectFrame name=iframe1
waitForElementPresent link=Images
clickAndWait link=Images
selectFrame relative=up
click link=AOL.com
selectFrame name=iframe1
waitForElementPresent id=ghnav-news
clickAndWait id=ghnav-news

Run above given example on this page. 1st “click” command will open AltaVista website inside above given iFrame. Now if i want to perform any action on AltaVista website inside iframe, i need to select an iframe in which AltaVista website is open. So next command “selectFrame” will select that iFrame. I have given “name=iframe1” in target column which is name attribute of iframe. Next command “waitForElementPresent” will pause selenium until “link=Images” appears on AltaVista website inside iframe and when specified element will appears on the page, next command will click on it. Now you can perform any action inside iFrame(on AltaVista website).

“relative=up” with selectFrame
using “relative=up” with “selectFrame” command, you can select parent window or parent page.
If you wants to work with multiple IFrame In webdriver then view THIS POST.

Now continuing to above example,  if you want to comeback on parent page to click on AOL website link, you need to use “relative=up” with “selectFrame” command. It will remove selection of iFrame and now you are on main page and you can click on “link=AOL.com”. So it will open AOL website inside the iFrame and you can perform your actions inside iFrame.

author avatar
Aravind QA Automation Engineer & Technical Blogger
Aravind is a QA Automation Engineer and technical blogger specializing in Playwright, Selenium, and AI in software testing. He shares practical tutorials to help QA professionals improve their automation skills.
Stay Updated with New Articles
Get the latest tutorials and insights delivered to your inbox.

One thought on “selenium “selectframe” command example with relative=up

Leave a Reply

Your email address will not be published. Required fields are marked *