Jump to content

Focus IE7 tab


Recommended Posts

I have made a nice script that fill out some web forms for me but i can't figure out how to make it switch to the tab i have attached to

I use this to identify my tab

$oIE = _IEAttach ("[my tab title]")

$handle = WinGetHandle("[my tab title]","")

then i use WinActivate($handle, "") to focus the window then grab form elements etc and it works fine even when the tab is not the active tab it will navigate and fill out the form etc. but i cant seem to figure out how to focus the tab.

i tried _IEattach("Windows Internet Explorer","embeded" = "[my tab title]") but i get errors

if i do _IEattach("Windows Internet Explorer","embeded") it attaches to whatever tab i'm on

how do I get IE7 to switch tabs? $oIE.focus is the wrong object type is there a similar function i can use ?

Link to comment
Share on other sites

I have made a nice script that fill out some web forms for me but i can't figure out how to make it switch to the tab i have attached to

I use this to identify my tab

$oIE = _IEAttach ("[my tab title]")

$handle = WinGetHandle("[my tab title]","")

then i use WinActivate($handle, "") to focus the window then grab form elements etc and it works fine even when the tab is not the active tab it will navigate and fill out the form etc. but i cant seem to figure out how to focus the tab.

i tried _IEattach("Windows Internet Explorer","embeded" = "[my tab title]") but i get errors

if i do _IEattach("Windows Internet Explorer","embeded") it attaches to whatever tab i'm on

how do I get IE7 to switch tabs? $oIE.focus is the wrong object type is there a similar function i can use ?

I have not figured out how to make the tabs come up selected (_IEAction( , "focus") didn't work), but this demo at least gives you the tabs to play with (requires IE7):
#include <IE.au3>
#include <Array.au3>

_IEErrorHandlerRegister()

Global Const $navOpenInNewTab = 0x0800; flag to open in a new tab

; Array of URLs for test
Global $avURLs[4] = ["http://www.google.com", _
        "http://www.autoitscript.com", _
        "http://www.ubuntu.com", _
        "http://www.OpenOffice.org"]

; Array of IE objects
Global $avIE[UBound($avURLs)]

; Open initial instance of IE
$avIE[0] = _IECreate($avURLs[0])

; Open extra tabs
For $n = 1 To UBound($avURLs) - 1
    __IENavigate($avIE[0], $avURLs[$n], 1, $navOpenInNewTab)
    $iTimer = TimerInit()
    Do
        $avIE[$n] = _IEAttach($avURLs[$n], "URL")
        If @error = 0 Then 
            _IELoadWait($avIE[$n])
            ExitLoop
        EndIf
    Until TimerDiff($iTimer) > 30000
Next

Sleep(5000)

; Get object references to the tab and get their URLs and titles
$sMsg = ""
For $n = 0 To UBound($avIE) - 1
    _IEAction($avIE, "focus"); <=== faild to bring the tabs up
    
    If IsObj($avIE[$n]) Then 
        $sMsg &= $n & ":  " & ObjName($avIE[$n]) & "  URL = " & _IEPropertyGet($avIE[$n], "LocationURL") & _
            "  Title = " & _IEPropertyGet($avIE[$n], "Title") & @CRLF
    Else
        $sMsg &= $n & ": Not an object" & @CRLF
    EndIf
Next
MsgBox(64, "Results", $sMsg)

Note this uses Dale's undocumented __IENavigate() (with two underscores) to open the additional tabs.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hmm. yeah i had seen that undocumented navigate a couple times in threads for creating new tabs. i also thought that _IECreateEmbedded would create a new tab. but even after creating them i cant figure out how to make the tab active.

well at least not in a good way. the tab I use I tend to keep on the far left (1st tab) i could probably find that control in the window and send a click but it's not nearly as reliable i could also send ^{tab} to go through the tabs but its hard to tell which one is active so it would be difficult to know when to stop. plus it might have to cycle a lot of tabs which would probably crash IE every now and then if i didn't slow the keys down to where i might as well just click it myself.

Link to comment
Share on other sites

This topic is definately worth expanding on. The _IE functions are mysterious at best. I have problems both with attaching and bringing to focus tabs and windows. Sometimes it works sometimes it doesn't. If anyone out there could lay out exactly how to get the proper way to attach and bring to "focus" a specific tab it would be greatly appreciated. I have done many searches in the past but haven't found good clear examples yet. Thanks

Link to comment
Share on other sites

This topic is definately worth expanding on. The _IE functions are mysterious at best. I have problems both with attaching and bringing to focus tabs and windows. Sometimes it works sometimes it doesn't. If anyone out there could lay out exactly how to get the proper way to attach and bring to "focus" a specific tab it would be greatly appreciated. I have done many searches in the past but haven't found good clear examples yet. Thanks

You should start your own topic for the specific issue you are having problems with. The _IE* functions in general are not mysterious at all, once you learn a few things about how IE and DOM work.

Tabs are a little mysterious because Microsoft choose for some reason not to include them in the COM interface of IE. The _IE* functions by Dale implement well known Microsoft APIs for IE in an easy to use AutoIt form. In the case of tabs, Microsoft did not provide and API, so the _IE* functions for that are not there.

From the issues you mentioned:

1. Attaching to tabs: Done. _IEAttach() works fine with tabs.

2. Bringing tabs to focus: No API available. Klunky situation-specific work-arounds are all you get for this right now.

3. Attaching to (IE) windows: Done. _IEAttach() works fine.

4. Bringing an (IE) window to focus: Done. _IEPropertyGet($oIE, "hwnd") then WinActivate() with the handle.

5. Intermittent behavior: More to do with your circumstances and code than AutoIt.

To get more help, start your own topic with specifics of what you want to happen, and what actually happens, with a short demo script to show your issue.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I wonder if IE8 does tabs differently or if any of the current library functions break in 8.

anyway i did manage to get my tab focused but i had to use ControlClick() so the script doesn't act quite right if the application I'm interested in isn't the first tab on the left. which isn't really a problem since that's the way it usually is i just have to be careful that it stays that way.

oh well hopefully a later update will have Tab controls.

Link to comment
Share on other sites

IE works hard to hide the fact that a page is in a tab. This is considered a security issue, so the DOM does not have access to tab controls. There are some keyboard shortcuts:

http://windowshelp.microsoft.com/Windows/e...0c1033.mspx#ESF

Working with tabs

The following table describes shortcuts used when working with tabs.

To do this

Press this

Open links in a new tab in the background

CTRL+click

Open links in a new tab in the foreground

CTRL+SHIFT+click

Open a new tab in the foreground

CTRL+T

Switch between tabs

CTRL+TAB or CTRL+SHIFT+TAB

Close current tab (or the current window if tabbed browsing is disabled)

CTRL+W

Open a new tab in the foreground from the Address bar

ALT+ENTER

Switch to a specific tab number

CTRL+n (where n is a number between 1 and 8)

Switch to the last tab

CTRL+9

Close other tabs

CTRL+ALT+F4

Toggle Quick Tabs (thumbnail view) on or off

CTRL+Q

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

PSaltyDS and Dale

Thanks for the info, I know I'm not being to specific in my problems, but I was basically just "crusing" the help forum and had remembered problems that I'd had previously. With my reinterest I was just putting my 2cents in and hoping to learn a little more. Truthfully I get overwhelmed pretty quick with the jargon and I hate not doing my homework before asking for specific help. The shortcuts will help with the workarounds. Thanks again for the patience as I continue to learn.

Link to comment
Share on other sites

  • 1 year later...

Are you sure that you want to post this as a hijack of someone else's old thread?

I was not sure, but its related to Dales reply here, anyway, I`ll create a new thread to keep everyone happy... :(

2015 - Still no flying cars, instead blankets with sleeves.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...