anthonyjr2

WinActivate keeps opening a new tab

21 posts in this topic

#1 ·  Posted (edited)

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.

Edited by anthonyjr2

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites



#2 ·  Posted

Bump, I'm still seeing this issue.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#3 ·  Posted

Use the IE UDF for this. WinActivate will open a new tab with the default start page if i is not already opened.

Share this post


Link to post
Share on other sites

#4 ·  Posted

I am using the IE UDF with an _IEAttach(). This problem occurs when I eventually want to switch back to the IE window from another program on my computer. Instead of going to my already-created tab it decides to create a blank new one.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#5 ·  Posted

Why should we get a new tab in IE when we just want to activate the window (independant of the application)?
Could this be a bug?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

1 minute ago, water said:

Could this be a bug?

It is possible. Did the issue happen to you when you ran my example code in my first post? I thought it was very strange that it opened a new tab as well.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#7 ·  Posted

I was running your modified code:

#include <Array.au3>
AutoItSetOption("WinTitleMatchMode", 2)
$aArray = WinList("Internet Explorer")
_ArrayDisplay($aArray)
$RC = WinActivate("Internet Explorer")
MsgBox(0, "", $RC & "-" & @error & "-" & @extended)
Exit

and it happened 1 out of 5 to 10 times.
I wonder why WinList returns much more Windows (even one empty tab) when I do not get some of them in the task bar.
Windows 7 with IE11.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

I'm on Windows 10 with IE11. The other weird thing is that it doesn't seem to ever open more than one new tab, even running it for 30+ iterations. Is there any way to see the source code of built-in functions such as WinActivate? They wouldn't be in the Include folder or anything. This bug basically makes it impossible to run one of my programs I've been working on, so I'll be adamant in trying to find a solution.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#9 ·  Posted

You could run WinList, grab the needed window and use WinActivate passing the Window handle from Winlist.
Drop

AutoItSetOption("WinTitleMatchMode", 2)

then.
Maybe IE creates hidden tabs (which get displayed by WinList). When using substring to match window titles the hidden tab gets selected and displayed by accident :huh:
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

You could totally be right about the hidden tabs thing. I will try dropping the substring match and see how it works. It's just slightly more inconvenient ;)

Although I definitely think it is an interesting bug.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#11 ·  Posted

I think it is the better solution as you activate the different IE windows in a controlled manner :)
Even when it takes two minutes more to code ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

16 hours ago, anthonyjr2 said:

I am using the IE UDF with an _IEAttach(). This problem occurs when I eventually want to switch back to the IE window from another program on my computer. Instead of going to my already-created tab it decides to create a blank new one.

IEAtach will attach to any IE window - no matter who created them. I dont understand why you need to use WinActivate for that !

Share this post


Link to post
Share on other sites

#13 ·  Posted

5 hours ago, Juvigy said:

I dont understand why you need to use WinActivate for that

Because I am switching between other programs other than IE. So I need to eventually go back to the IE window. This has nothing to do with the IE UDF or _IEAttach at all.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#14 ·  Posted

I still dont get it. You can switch between programs and still after that you can use IEAtach to attach to the IE window. Use winactivate to activate other programs , but for switching to IE use the IE UDF.

Share this post


Link to post
Share on other sites

#15 ·  Posted

Because I have already attached to the window once in the beginning of the script. There is no reason for me to attach to the window every time I want to bring it to the front and make it active again when I already have the handle from the first attach. As I stated earlier I am already using the IE UDF, the problem I was having has nothing to do with that.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#16 ·  Posted

Since you already have the IE object reference, have you tried just using it without performing the WinActivate? If so, what was the outcome?

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

That works fine, the only issue is that I need to do some OCR on the window, which is why I need it to be the topmost window. Otherwise yeah I could just perform actions without it being active.

I realize that this is getting slightly off topic. In any case my problem is basically resolved after dropping WinTitleMatchMode = 2, I just had to be more specific in the WinActivate. This definitely makes me think that water was correct in his assumption about the blank hidden IE windows.

Edited by anthonyjr2

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#18 ·  Posted

Have you tried this --

WinActivate(HWnd($oIE.hWnd))

where $oIE is the existing reference to your IE tab?

Share this post


Link to post
Share on other sites

#19 ·  Posted

If you have the reference to the IE tab - you can activate it using the IE DOM.

Share this post


Link to post
Share on other sites

#20 ·  Posted

@Danp2 I'll give that a shot when I get a chance.

@Juvigy Do you mean doing it the way Danp2 suggested?


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
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

  • Similar Content

    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • electrons
      By electrons
      hi  , hope  you all doing well 
       cant find any elements on the page ?  and the right click mouse dont work too?
      iam trying with more than method , i need help please!!
       

    • ur
      By ur
      I have kept below line to wait for IE to load the site completely and continue.
      _IELoadWait($oIE)
       
      But, the code is continuing without waiting for it and I my execution is failing as the elements are not loaded completely.

       
      Any suggestions for alternate code to wait for the browser to load completely?
       
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help