Page 1 of 1

User code for close all browsers not working for EDGE

Posted: Wed Sep 27, 2017 1:02 pm
by phiomet
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

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

Posted: Wed Sep 27, 2017 8:03 pm
by krstcs
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.

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

Posted: Thu Sep 28, 2017 3:16 pm
by Support Team
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
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