selenium "selectframe" command example with relative=up

"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

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 "". So it will open AOL website inside the iFrame and you can perform your actions inside iFrame.

1 comment: