How to close Edge browser or a tab?

Ranorex Spy, Recorder, and Studio.
samantha.chin
Posts: 10
Joined: Mon Dec 28, 2015 10:17 am

How to close Edge browser or a tab?

Post by samantha.chin » Mon Dec 28, 2015 10:23 am

Hi,

I wrote a piece of code that will find a specific URL and close the browser/tab before proceed to next steps. Eg as below :

public void CloseAlBrowsers()
{

IList<Ranorex.WebDocument> AllDoms = Host.Local.FindChildren<Ranorex.WebDocument>();
foreach (WebDocument myDom in AllDoms)
{
//Report.Log(ReportLevel.Info,"BrowserDOM",myDom.PageUrl);
if (myDom.PageUrl.Contains("Google") && myDom.PageUrl.Trim() != "")
{ myDom.Close(); }
}
}

However, this code cannot close the EDGE browser and hit error message "Action 'close' failed on element '{WebDocument:Google}'." Appreciate your assistance. Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to close Edge browser or a tab?

Post by Support Team » Mon Dec 28, 2015 1:00 pm

Hello samantha.chin,

The issue is already known and we are currently working on a solution.

In the meantime you could use the following workaround.
First, add the corresponding tab to the repository.
edge_spy.png
edge_spy.png (9.56 KiB) Viewed 2283 times
edge_tab.png
edge_tab.png (6.96 KiB) Viewed 2283 times
Within the user code method you could check if the current WebDocument is opened in Microsoft Edge.
If this is the case, a click on the corresponding tab is performed and the tab is closed via the key sequence "CTRL+F4".

Code: Select all

IList<Ranorex.WebDocument> AllDoms = Host.Local.FindChildren<Ranorex.WebDocument>();
foreach (WebDocument myDom in AllDoms)
{	
	if (myDom.PageUrl.Contains("Google") && myDom.PageUrl.Trim() != "")
	{ 
		if ( myDom.BrowserVersion == "Microsoft Edge" )
		{
			repo.MicrosoftEdge.Google.Click();
			Keyboard.Press(System.Windows.Forms.Keys.F4 | System.Windows.Forms.Keys.Control, 62, Keyboard.DefaultKeyPressTime, 1, true);
		}
		else
		{
			myDom.Close();	
		}
					
	}
			
}
I will update this thread when I have new information about the status of the issue.

Regards,
Johannes
.
Image

samantha.chin
Posts: 10
Joined: Mon Dec 28, 2015 10:17 am

Re: How to close Edge browser or a tab?

Post by samantha.chin » Tue Dec 29, 2015 2:09 am

It's worked! Thank you.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to close Edge browser or a tab?

Post by Support Team » Fri Jan 29, 2016 1:28 pm

Hello,

The issue was fixed in the latest version of Ranorex, 5.4.5.
The WebDocument.Close() action works now for DOMs in Edge, too.

Sincerely,
Johannes
.
Image