Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting tab in firefox
#1
Hi all

after identifying the desired tab with Firefox4GetTabs function, what is the more efficient way to switch to it
by using its name or position? Upposing i'm currently on 2nd tab, i want to switch to 4th one, or to a tab named
"thetabiwanttogoto"?

Thanks
#2
Acc.Find delay
An old blog on QM coding and automation.

The Macro Hook
#3
Thanks for the input Ken, but you point the link to the macro i refer in my post to actually find a tab, it's name and row place.

What i'd like is the way to switch to the desired tab, knowing it's name or postion.
#4
Updated 2014-04-30.
If does not work with portable Firefox: FireFox portable and FireFox functions (FirefoxGetTabs, ..)

This version gets accessible objects of tab buttons.
Also changed:
1. Renamed from Firefox4GetTabs to FirefoxGetTabs.
2. Error if does not find window or something fails.
3. names is optional, can be 0.

Function FirefoxGetTabs
Code:
Copy      Help
;/
function# [hwndFF] [ARRAY(str)&names] [ARRAY(str)&urls] [ARRAY(Acc)&docObjects] [ARRAY(Acc)&buttonObjects]

;Gets names of Firefox tabs. Optionally gets their URL and accessible objects.
;Returns 0-based index of the selected tab.
;Error if fails.

;hwndFF - Firefox window handle. If 0, finds.
;names - variable for tab names. Can be 0 if don't need.
;urls - variable for addresses. Can be 0 if don't need.
;docObjects - variable for DOCUMENT accessible objects that represent web pages. Can be 0 if don't need.
;buttonObjects - variable for PAGETAB accessible objects that represent tab buttons. Can be 0 if don't need.

;REMARKS
;Requires QM 2.3.3 or later.
;Elements of urls and docObjects of non-loaded tabs will be empty. Firefox does not load pages in invisible tabs at startup.

;EXAMPLE
;ARRAY(str) names urls
;int selectedTab=FirefoxGetTabs(0 names urls)
;out selectedTab
;int i
;for i 0 names.len
,;out "--------[]%s[]%s" names[i] urls[i]


ARRAY(str) _names; if(!&names) &names=_names
names=0
if(&urls) urls=0
if(&docObjects) docObjects=0
if(&buttonObjects) buttonObjects=0

if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) end ERR_WINDOW

int i r=-1
FFNode fn
ARRAY(str) ap

;enum tabs
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004 1) ;;note: added 1 s waiting because fails when called first time after launching FF
rep
,if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
,
,names[]=a.Name
,if(&buttonObjects) buttonObjects[]=a
,
,;get selected tab
,if(r<0 and a.State&STATE_SYSTEM_SELECTED) r=i
,
,if &urls
,,;get id of associated pane and store in ap. Because the order of tabs and panes may be different.
,,fn.FromAcc(a)
,,ap[]=fn.Attribute("linkedpanel")
,
,;next
,a.Navigate("n"); err break
,i+1

if(r<0) end ERR_FAILED
if(!&urls and !&docObjects) ret r

;enum panes
if(&urls) urls.create(names.len)
if(&docObjects) docObjects.create(names.len)
#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
#else
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
#endif
rep
,;get id of this pane, and find in ap
,fn.FromAcc(a); _s=fn.Attribute("id")
,for(i 0 ap.len) if(ap[i]=_s) break
,if(i=names.len) goto next2 ;;should never happen
,;get DOCUMENT object and url
,Acc aa; a.Navigate("fi2" aa); err goto next2
,if(&urls) urls[i]=aa.Value
,if(&docObjects) docObjects[i]=aa
,
,;next2
,a.Navigate("n"); err break

ret r

err+ end _error

Function FirefoxSelectTab
Code:
Copy      Help
;/
function hwndFF $name [flags] ;;flags: 1 name is URL, 2 wildcard, 4 beginning, 8 end, 16 anywhere, 32 rx

;Finds and select Firefox tab.
;Error if not found.

;hwndFF - Firefox window handle. If 0, finds.
;name - tab name. If flag 1 - URL.
;flags:
;;;1 - name is URL.
;;;2-32 - how to compare name. Default: exact match. Always case insensitive.
;;;

ARRAY(str) names urls; ARRAY(Acc) a
int selectedTab=FirefoxGetTabs(hwndFF names iif(flags&1 &urls 0) 0 a)
int i
ARRAY(str)& as=iif(flags&1 urls names)
for i 0 names.len
,if SelStr(flags|1 as[i] name)
,,if i!=selectedTab
,,,a[i].DoDefaultAction
,,ret 1

end "tab not found"
err+ end _error

Or simply find and click tab button accessible object.
Acc a.Find(... "PAGETAB" ...)
a.DoDefaultAction
#5
GAHHHH!!!! I need to start drinking coffee!

sorry about that. here's a skeleton that'll do that. you should be able to change the "Inbox * - Gmail" string to be a variable that you pull out of the array after using the Firefox4GetTabs.

Macro Macro
Code:
Copy      Help
int w1=win("* - Mozilla Firefox" "Mozilla*WindowClass" "" 0x805)
Acc a1.Find(w1 "PAGETAB" "Inbox * - Gmail" "class=MozillaWindowClass" 0x1005)
a1.Mouse(1)
An old blog on QM coding and automation.

The Macro Hook
#6
yeah...ok, I guess you could do that thing G just wrote up too....I guess... :lol:
An old blog on QM coding and automation.

The Macro Hook
#7
Hmmm, no way of doing that...simpler????

I managed to do Acc.mouse(1), but not very effective because two tabs with same name does mess.

Let's cook your code Gintaras.

Aren't tabs able to be selected or activated, or focused to bring them to front?
#8
What can be simpler than this?

FirefoxSelectTab 0 "name"
or
FirefoxSelectTab 0 "url" 1
#9
Sometimes, i want understand what is in my code, to reuse it suited for my needs, and yours is so advanced that i
hardly can get the meaning.

It's simple for you, not necessarily for end user.

When Federer plays tennis, i feel like it is simple 'til i try to hit a ball myself.......
#10
I think your supposed to use it like this

Macro Macro
Code:
Copy      Help
FirefoxSelectTab(0 "Inbox" 16)
An old blog on QM coding and automation.

The Macro Hook
#11
Well, for once the way Gintaras took was not appropriate, even if i used piece of code in another macro yet.....

The trick i was looking for was the dodefaultaction thing, baffled i did not find it by myself.

I just had then to tweak the original Firefox4GetTabs function, and off we go.

here what i did:

ARRAY(str) names urls
int selectedTab=Firefox4GetTabs(0 names urls)

int i

int w=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804)
Acc a.Find(w "PAGETAB" names[2] "class=MozillaWindowClass" 0x1005) => find by name
Acc a.Find(w "PAGETAB" "" "class=MozillaWindowClass" 0x1005 0 2) =>find by index
a.DoDefaultAction

Thanks again G & Ken for leading me the right way.
#12
a little follow up : what is the way to go for triggering an action on tab change : new tab creation, tab destroy, tab name change, lost/gain focus, change selected tab etc?
#13
For some events will work "window name changed" trigger.
For some should work accessible object trigger.

Or run a macro (function) that repeatedly gets tabs with FirefoxGetTabs and using that info decides what is changed.
#14
Hi Gintaras

seems it does not work anymore. Don't know if it's my setup or common to all firefox users (28-29 versions).

No more linkedpanel attribute in Acc dialog selection box.

Confirm?

TY
#15
Updated. Works with Firefox 29.
If portable Firefox: FireFox portable and FireFox functions (FirefoxGetTabs, ..)
#16
Does work for finding tabs, but fails to find panel and urls here...

Function FirefoxGetTabs
Code:
Copy      Help
,fn.FromAcc(a); _s=fn.Attribute("id")
,for(i 0 ap.len) if(ap[i]=_s) break

tweaked

Function FirefoxGetTabs
Code:
Copy      Help
,fn.FromAcc(a); _s=fn.Attribute("id")
,out _s
,for(i 0 ap.len) if(ap[i]=_s) break

_s is always empty...
#17
In dialog 'Find accessible object', in 'Other properties', are there some items that begin with "a:"? Test with tab buttons. Also test with some links, should be "a:href". If all "a:" are missing, try to run macro "Firefox portable install registry values for QM functions" from the above link, and restart Firefox.
#18
regular firefox not portable mode.

used to work til version 27 t last..


Forum Jump:


Users browsing this thread: 1 Guest(s)