Trying to close tab with PDF viewer plugin loaded

Jan 17, 2013 at 2:51 PM

Hi,

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:

<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height;">
<title>DocumentLookup (application/pdf Object)</title>
</head>
<body marginwidth="0" marginheight="0">
<embed width="100%" height="100%" name="plugin" src="https://someserver.com/FUTUREDEV_OLB_AUTOMATION/Document/DocumentLookup" type="application/pdf">
</body>
</html>

 

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?

Thanks

Jeff

 

 

 

Jan 17, 2013 at 6: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"))
                {
                    theProcess.Kill();
                }
            }
            //Send a close tab message to the browser
            Keyboard.SendKeys("^(W)");

Hope it helps someone.

Thanks

Jeff

 

Coordinator
Jan 19, 2013 at 7: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.