Trying to close tab with PDF viewer plugin loaded

Jan 17, 2013 at 3:51 PM


I'm wondering if anyone has run into this before.  I am clicking on a button in a web application that launches a new browser tab and loads a PDF into a plugin.  We are using IE9.  I want to close the tab with the loaded PDF but can't figure out a way to do this with the automation.

Here is the html that is loaded:

<meta name="viewport" content="width=device-width; height=device-height;">
<title>DocumentLookup (application/pdf Object)</title>
<body marginwidth="0" marginheight="0">
<embed width="100%" height="100%" name="plugin" src="" type="application/pdf">


I tried to send a keyboard shortcut (CTRL+W) to close the tab but the PDF plugin is intercepting this shortcut and doesn't allow it to get through to the browser.

Any other ideas on how to handle this?






Jan 17, 2013 at 7:01 PM

I came up  with a solution for this that I thought I would post.  When the PDF is loaded in the PDF reader plugin it starts a AcroRd32 process on the server.  My solution is to kill that process which closes the PDF in the browser and then close the tab with a sendkeys command.  Not very pretty but it works.  Here is the code:

            Process[] processList = Process.GetProcesses();
            //Go through each of the running processes and see if the process is Acroreader.  If the reader is found then kill it.
            foreach (Process theProcess in processList)
                if (theProcess.ProcessName.Contains("AcroRd32"))
            //Send a close tab message to the browser

Hope it helps someone.




Jan 19, 2013 at 8:25 PM

Hi Jeff,

Can the Coded UI test recorder built-in to Visual Studio 2010 record and playback those actions without issues?

You may also try to disable tabbed browsing in Internet Explorer's options to see if it makes your code easier\better.

Thank you.