User code for close all browsers not working for EDGE

Class library usage, coding and language questions.
phiomet
Posts: 1
Joined: Wed Sep 27, 2017 12:55 pm

User code for close all browsers not working for EDGE

Post by phiomet » Wed Sep 27, 2017 1:02 pm

Hello,

first, i´m not very in with coding oder development, so i have a user code from another project for closing all browser windows.
i tried to use it, it works for Firefox, IE and Chrome but not for the EDGE browser. I need a little assistance, what i have to change on this code to make it work also with EDGE.

Code: Select all

        public void closeAllBrowserTabs(){
        	Report.Info("attempting to close open browser windows...");
        	
        	IList<WebDocument> wdList = Host.Local.Find<WebDocument>("/dom");
        	Report.Info("open browser windows: "+wdList.Count);
        	
        	foreach(WebDocument wd in wdList) {
    			wd.EnsureVisible();
    			
    			if(wd.Visible) {
        			try {
	    				wd.Close();
	    			} catch(Ranorex.ActionFailedException e) {
	    				Report.Warn("failed to close browser window/tab: "+e.Message);
	    			}
        		}
    		}
        	
        	Delay.Milliseconds(500);
        }
Ranorex is Version 7.1.2 on Windows 10 with Microsoft Edge 38.14393.1066.0.

Thank you and regards
Alex

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: User code for close all browsers not working for EDGE

Post by krstcs » Wed Sep 27, 2017 8:03 pm

Ranorex does not work with Edge DOMs unless you are using a WebDriver endpoint. This is an issue with how MS designed Edge, and there is nothing Ranorex can do about it.

Your options are to (a) use a WebDriver endpoint (best option), (b) close Edge's window directly instead of using the DOM.

Really, the ONLY option is to use WebDriver with web pages from this point forward, otherwise you won't be able to do any testing with Edge, and that would mean making special tests for Edge vs everything else. If you use WebDriver endpoints, though, you can test all browsers from the same test suites.
Shortcuts usually aren't...

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

Re: User code for close all browsers not working for EDGE

Post by Support Team » Thu Sep 28, 2017 3:16 pm

As krstcs mentioned, Ranorex has limited object recognition in Edge's DOM unless using a WebDriver, however, it can access and interact with the Edge form to close it. To close Edge without code, use "Close Application" or "Invoke Action > Close()".

RxPath of "MicrosoftEdge" element: /form[@title='Microsoft Edge']
ActionTable.png
ActionTable.png (9.76 KiB) Viewed 986 times
To close all Edge windows dynamically, use the below code.

Code: Select all

IList<Form> edgeBrowsers = Host.Local.Find<Form>("/form[@title='Microsoft Edge']");
foreach (Form edgeBrowser in edgeBrowsers)
	edgeBrowser.Close();
I hope this helps!

Cheers,
Ned
.
Image