Jump to content

WinActivate keeps opening a new tab


Recommended Posts

  • 2 years later...
On 6/17/2017 at 12:23 AM, anthonyjr2 said:

I have come across a weird issue that I am not sure how to solve. For some reason, whenever I call WinActivate in certain scenarios instead of opening the single window that already exists, it will create a new blank tab. It should be able to be recreated with this:

AutoItSetOption("WinTitleMatchMode", 2)

Sleep(1000)

For $i=0 To 10
    WinActivate("Internet Explorer")
Next

I am not actually doing this in my code, it is just to demonstrate the fact that new tabs keep popping up. Does anyone know why this happens?

 

EDIT: So I am not sure how reproducible this is, because it only happens every once in a while for me. I will update with more info if I find out anything.

I tried your given code and sure enough, found the bug you described,

However, I tried the following modification which seems to have solved the bug for me

Opt("WinTitleMatchMode",2)
For $i=0 To 10
    WinActivate("Notepad++")
    Sleep(100)
    WinActivate("Internet Explorer")
Next

FYI, I edit the autoit code in Notepad++ and run it directly from a shortcut called "Shell execute current file".

But, however, if you change the above code to 

Opt("WinTitleMatchMode",2)
For $i=0 To 10
    WinActivate("Notepad++")
    Sleep(100)
    WinActivate("Internet Explorer")
    WinActivate("Internet Explorer")
Next

the bug reappears in almost 100% of the attempts. Maybe there's a clue here.

Link to comment
Share on other sites

  • 2 years later...

Same issue for me other the years but was never so bad that I had to investigate, but now I do and my solution is to close all open IE tasks (check TaskManager since e.g. Outlook also keeps IE tasks open). Only after restarting IE the effect doesn't occurs and script runs reliable for the "script session"

Link to comment
Share on other sites

#include <WinAPISysWin.au3>
#include <Array.au3>
#include <WinAPISys.au3>
#RequireAdmin
#comments-start

Made by Ad777
#comments-end
_displayMultiWindow("Internet Explorer",1,2,100)


#comments-start
Function Name : _displayMultiWindow
Parameters:
////////title:name of the window
///////start:start number to be searched Default = 1
//////end:end number of searching ex:3 OR 10
//////Sleep:sleep for while ex:100
#comments-end
#comments-end
Func _displayMultiWindow($title,$start,$end,$sleep)
Local $aArray = WinList($title)
   For $i = $start To $end Step 1
      _WinAPI_SetForegroundWindow ($aArray[$i][1]);;;
      Sleep($sleep)
Next
   EndFunc

I HOPE THIS HELP YOU ☺️

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...