Forum Discussion
OK, two questions:
1. Where is it doing the long wait? Closing the browser or terminating the process?
2. Are you trying to terminate the process AFTER your original code to close the browser (which didn't seem to be closing it properly)?
I just tried your code (slightly modified to C# Script syntax as that's what I'm using) and it worked just fine. Closed an open instance of IE for me. No "invisible" process left running afterwards. Running Win 7 Pro 64. IE11. TC 11.20.
I'm stating to think there is something funky about your IE install causing this. Try getting rid of the original browser close attempt and just kill the process without attempting to close the browser first. Although, if there are already two instances present (your browser close error suggests there are) then it will only kill the first one. I just tried it with two browsers opened. Without specifying an index number. And it only closed the first one.
If you (somehow) have multiple instances of the process present, I think you'll need to loop through them one by one killing them.
Although, I'd be more interested to find out what's causing the second, invisible, instance to be there. As you clearly seem to think it shouldn't be ....
First of all I try to close the browser (IE browser). Then I check for the iexplore process if running.
If yes then I close the process too.
Also yesterday I re-installed- Internet explorer 11 and Testcomplete12 (of course completely uninstalled first ).
And I am working with single tab of internet explorer only.
Find the code below,
if(Sys.WaitBrowser().Exists)
{
Sys.Browser().Close();
Delay(5000);
}
var process = Sys.WaitProcess("iexplore", 5000);
if (process.Exists)
{
process.Terminate();
}
var url = Driver.Value(0).toString();
Browsers.Item("iexplore").Run(url);
Sys.Browser().BrowserWindow(0).Maximize();
page = Sys.Browser("iexplore").Page(url);
- Colin_McCrae9 years agoCommunity Hero
kjadhavkunal wrote:The problem was with my machine. Though I re-installed internet explorer11. There was 'iexplore.exe' service running even if we close the browser.
Did you manage to fix it in the end?
Interested to hear how if you'd already tried re-installing IE, and that didn't fix it first time ....
** EDIT **
I'm not sure the code from sanjay0288 would work here as it relies on counts of browsers to determine loop lengths. And I'm not sure if the invisible one in this case would be caught that way.
However, if you modified to look for all instances of the "iexplore*" process (with the wildcard there to catch any "*32" versions) and kill those, it might have done it. Even with the dodgy invisible version hiding in the background.
ie. Use processes to drive the loop. Not browser instances.
- tristaanogre9 years agoEsteemed Contributor
Eh, it was a wild guess, really.
The only thing I can think of is that something in the OS fires up an iexplore instance. I know I've seen this in Windows 7 and Windows 8 that there is some sort of Windows process that utilizes iexplore and so it's almost always open. Unfortunately, that was a few years back and I don't recall the solution. - sanjay02889 years agoFrequent Contributor
Kill the instances at the process level. The code to achieve the same has already been shared in the previous posts.
For the second part of the problem not sure why the process always be in running state. Because of the addons you could be facing this issue. You can try going through the below mentioned link to figure out the root cause of the problem.
- Colin_McCrae9 years agoCommunity Hero
Re-read my previous post.
Your reply above adds nothing new to your previous post.
Try terminating the process INSTEAD of closing the browser. Comment the part about closing out or something.
Your code isn't going to work if there are multiple instances of the process present as it is explicitly written to only address one of them. If there is a second process present, it will never get to it.
You can either address them by index. Or go the more brute force route. Either way, you need it in a loop.
Try modifying the termination part to (my bits are blue & psuedocode .. I think this is jScript, which I don't use):
Do
var process = Sys.WaitProcess("iexplore", 5000);
if (process.Exists)
{
process.Terminate();
}
Loop Until (Not Process.Exists)
- tristaanogre9 years agoEsteemed Contributor
OK... here's a question... how are you launching your browser? And are you launching the 64 bit version of the browser and not the 32-bit? I wonder if what we're dealing with here is that TC is a 32-bit app and, if you have a 64-bit instance of the browser running, I'm not 100% certain that TC will properly detect and close it.
Just a thought... - Colin_McCrae9 years agoCommunity Hero
tristaanogre wrote:
I wonder if what we're dealing with here is that TC is a 32-bit app and, if you have a 64-bit instance of the browser running, I'm not 100% certain that TC will properly detect and close it.
I think it's OK with that. If I start the browser myself, but have TC kill it through the process, it's fine. And it's the 64 bit version that starts when I run it manually. Works equally as well if the browser was launched by TC.
- Colin_McCrae9 years agoCommunity Hero
I *think* (not 100% sure here) that if TC fires the browser instance, it may start the 32 bit version.
I start mine with a shell object and use that to run the executable. But I don't give a file path. Just the browser name. The OS/application figures it out. But I do recall seeing both "iexplore" and "iexplore*32" in the process list. But that's never caused me any issues opening and closing browsers.
But then, I do use Chrome 95% of the time (although I do routinely have 4 or 5 open at a time). And I just use the "Close" method of the Page object. I don't kill the process. If IE (or Chrome) doesn't close properly for some reason, it's regarded as a test failure and reported as such. We prefer to catch things like this rather than paste over them by killing the process in case it's something we've done that's causing the hang.
Still not sure where the second instance is coming from in this case ....
- kjadhavkunal9 years agoContributor
Hello all,
Thank you so much for all your solutions. The problem was with my machine. Though I re-installed internet explorer11. There was 'iexplore.exe' service running even if we close the browser.
I did not notice this behaviour before. May be this is because of activation of 'add-ons'.
Please let me know if anyone is facing the same.
- shankar_r9 years agoCommunity Hero
Colin_McCraementioned, you can close the browser instances using process like below
function test() { var tempBrowsers = Sys.FindAllChildren("ProcessName","iexplore"); for(var i=0;i < tempBrowsers.length ; i++) { tempBrowsers[i].Close(); aqUtils.Delay(5000,"Wating for IE to close"); } } - Colin_McCrae9 years agoCommunity Hero
shankar_r .... that could miss some. You're only searching for "iexplore". There can also be "iexplore*32" instances (which are something to do with tabbed browsing from what I can gather). I believe it's possible for these to get left behind when IE is closed (sounds like that was what was happening to kjadhavkunal). Hence why I included the "*" wildcard.
- shankar_r9 years agoCommunity Hero
Got you Colin_McCrae, I changed the code like below
function test() { var tempBrowsers = Sys.FindAllChildren("ProcessName","iexplore*"); for(var i=0;i < tempBrowsers.length ; i++) { tempBrowsers[i].Close(); aqUtils.Delay(5000,"Wating for IE to close"); } }As per my understanding, If we have IE with multiple tabs, each tab will have one separate process allocated hence above code should work for multiple tabs or multiple browser instances.
- Colin_McCrae9 years agoCommunity Hero
Yup. That should do it. Haven't actually tried it, but it looks right to me.
- sanjay02889 years agoFrequent Contributor
oh bad. I missed out the actual point. You can use WMI to terminate all the instances of IE.
strComputer = "."
strProcessToKill = "iexplore.exe"
SET objWMIService = GETOBJECT("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
SET colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")FOR EACH objProcess in colProcess
objProcess.Terminate()NEXT
- kjadhavkunal9 years agoContributor
As I said before, its not about closing instances of a browser. I am able to see the browser is closed. But when I go to Task Manager, there is process for the same in running state.
Also, it was working fine on my machine yesterday. When I returned back from 30 minutes break again found the same issue. Currently working from another machine. Is it something machine specific?
Please help with the solutions.
Thank you in advance!
- Colin_McCrae9 years agoCommunity Hero
The last few posts ARE the solution!
Kill it at process level. Simply make sure you find and terminate all the possible variations of the process. It's pretty simple to do. A search with a wildcard (or two searches if using a * to search for a * doesn't work), and then a loop (or loops - but easy enough to get both search results into the same array if you do two searches) to kill off the found processes.
That should get round the problem., But no idea why your PC is leaving bits of process behind.