cancel
Showing results for 
Search instead for 
Did you mean: 

Exiting out of a frame using JavaScript

SOLVED
Highlighted
Contributor

Exiting out of a frame using JavaScript

Hi,

 

I'm working on web application for GUI automation testing. The application web-page has few iFrames within which there are web-elements defined. For better performance of element identification, I switch to the frame and then search for the web-element. After this is completed, I would like to switch back to the default content (which is not an iFrame) and proceed with element identification and rest of the execution.

 

How to proceed in this scenario? The Frame method needs an index or name - https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/web-objects/frame-met...

 

But I can't use this to switch back to default content as it is not an iFrame. I have tried the below approaches but no success:

 

1) Store the current page before navigating to iFrame in a variable. Then I passed this variable to a function - getMainTabUsingPage(page) which gets the Main tab web object present outside the iFrame (default content).
 
Code snippet:
var page = Sys.Browser().Page("*");
 
getMainTabUsingPage(page) {
let xpath = "//div[@class=\"topmenu\"]/table/tbody/tr/td[contains(text(),'MainTab')]";
let myTabObj = page.FindChildByXPath(xpath);
return myTabObj;
}
 

 

2) Refresh the page after switching to iFrame, to reload the page with entire HTML DOM of the webpage so that the MainTab web element can be found in the DOM.

 

Please suggest/help. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Hi,

 

Like Marsha wrote...

TestComplete, unlike Selenium, does not switch to iframe and does not need to switch back. It just assesses elements as they are displayed in the Object Browser.

E.g. (pseudocode):

page.frame(1).button('subscribe').Click();

Log.Message(page.Panel('subscriptionCounter').wText);

page.frame(2).button('sendInvite').Click();

...

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

3 REPLIES 3
Highlighted
Community Hero

Is the default content still on screen when you are in the other frames?  You could just add a click on a tab or a field that you can still see in order to change the focus.

Highlighted
Community Hero

Hi,

 

Like Marsha wrote...

TestComplete, unlike Selenium, does not switch to iframe and does not need to switch back. It just assesses elements as they are displayed in the Object Browser.

E.g. (pseudocode):

page.frame(1).button('subscribe').Click();

Log.Message(page.Panel('subscriptionCounter').wText);

page.frame(2).button('sendInvite').Click();

...

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Contributor

Hi @Marsha_R  and @AlexKaras ,

 

Thanks for your responses. Sorry I will add some more background details for a better understanding.

 

I earlier tried directly identifying the elements and performing the click option. It works fine but the performance was very bad as there were similar objects with huge data in the same page, so it was taking long time to find the element. So the workaround for this was that I find the element using the specific iFrame in which the element belongs. This has improved the performance as the scope of searching for element reduced.

 

@Marsha_R  Yes the 2nd element (MainTab) is still visible after I switch the frame.

 

@AlexKaras and @Marsha_R - I am not sure if the control switches to the iFrame when I find the element or it just looks within the specific frame without switching the control. Below is the detailed code flow I used to find the element in the iFrame named "iFrame_sr". After below code flow is when I'm trying to click on second element which is outside of iFrame scope.

 

//get the frame object in which element is present, using the name of the iFrame.

let frame = tcHelper.GetiFrameObject(this.getWebPage(),"iFrame_sr"); // refer below section for function body

 

//get the web element object by searching in the frame object received from the above code using the ID of the webelement

let webObj = tcHelper.GetWebObjectInFrameWithID(frame,webEleId); // refer below  section for function body

 

//Args: webPageObj is the page in which iFrame is present. iframeID is the ID of the iframe being captured
GetiFrameObject(webPageObj,iframeID){
let iframe = webPageObj.contentDocument.getElementById(iframeID);
if(iframe==null)
Log.Error("Unable to find the iframe object with ID: "+iframeID+" in the webpage");
else
return iframe;
}

GetWebObjectInFrameWithID(frameObj,webElementID){
let webObj = frameObj.contentDocument.getElementById(webElementID);
if(webObj==null)
Log.Error("Unable to find the web object with ID: "+webElementID+" in the specified frame of the webpage");
else
return webObj;
}

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get properties of a web page element

See replies!

Compare images using the Region Checkpoint

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors