Error while attempting to close IE browser

Ask general questions here.
Noah
Posts: 11
Joined: Tue Aug 21, 2018 1:31 pm

Error while attempting to close IE browser

Post by Noah » Thu Jan 03, 2019 10:38 am

Hello all,

I have a scenario in my test case where i'm supposed to close browsers and below is the code for reference and this code works great with chrome and firefox where as in IE I'm ending up with exception errors.

public void closeBrowsers()
{
try{

IList<Ranorex.WebDocument> browsers = Host.Local.FindChildren<Ranorex.WebDocument>();

for(int i=0; i<browsers.Count; i++)
{
browsers.Close();
Delay.Seconds(2);
Report.Info("Closing Browsers");
}
}

catch(RanorexException e){

Report.Info("Closing browsers exception caught:" +e);
}

}

Exception Error:
++++++++++++++++++

08:14.379 Info User

Closing Browsers
08:14.409 Info User
Jump to item
Closing browsers exception caught:Ranorex.ActionFailedException: Action 'close' failed on element '{WebDocument:IE}'. ---> System.Runtime.Remoting.RemotingException: Failed to write to an IPC Port: The pipe is being closed.


Server stack trace:
at System.Runtime.Remoting.Channels.Ipc.IpcPort.Write(Byte[] data, Int32 offset, Int32 size)
at System.Runtime.Remoting.Channels.Ipc.PipeStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Stream stream)
at System.Runtime.Remoting.Channels.Ipc.IpcClientHandler.SendRequest(IMessage msg, ITransportHeaders headers, Stream contentStream)
at System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Ranorex.Plugin.TridentIpc.ITridentDom.SetDocumentValue(IntPtr browserRef, String name, String val)
at Ranorex.Plugin.WebDocumentRemoteFlavorElement.InvokeAction(Element element, String name, Object[] args)
at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
--- End of inner exception stack trace ---
at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
at Ranorex.WebDocument.Close()
at Itte.CodeModules.Misc.Commonmethod.closeBrowsers() in c:\Users\jos.johnson\Documents\Ranorexstudioprojects\Itte\CodeModules\Misc\Commonmethod.cs:line 128
You do not have the required permissions to view the files attached to this post.

Vega
Posts: 222
Joined: Tue Jan 17, 2023 7:50 pm

Re: Error while attempting to close IE browser

Post by Vega » Thu Jan 03, 2019 10:26 pm

More than likely you are trying to close an embedded IE webdocument. For example Skype and other programs often have an IE document embeded within them and you cant close them like that. Your current implementation is trying to close every webdocument without bias, I would recommend making your path more specific by checking the domain:

Code: Select all

IList<Ranorex.WebDocument> domList = Host.Current.Find<Ranorex.WebDocument>("/dom[@domain='www.google.com']");
        
        	foreach(Ranorex.WebDocument dom in domList)
        		dom.Close();
You can test this out by opening Spy and just searching with the Ranorex Path

Code: Select all

//DOM
and see what is returned, you may be surprised which applications may have an embeded DOM.

Keep in mind the above example will only close browsers or tabs which match the domain so you may need to adjust for your scenario.

Hope this helps