Fr33b0w Posted August 17, 2017 Share Posted August 17, 2017 (edited) Is there any way that autoit can detect how many TABs are open in firefox browser? Or any other workaround method to do so? Help would be gladly appreciated. Edited August 27, 2017 by Fr33b0w Link to comment Share on other sites More sharing options...
water Posted August 17, 2017 Share Posted August 17, 2017 What have you tried so far? Did you check the Firefox UDF? Fr33b0w 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Danp2 Posted August 17, 2017 Share Posted August 17, 2017 This can be done with _FFGetLength. Fr33b0w 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 26, 2017 Author Share Posted August 26, 2017 A simple code like this worked: $tabs=_FFGetLength("tabs") If $tabs > 5 Then Send("^{F4}") Sleep(1000) EndIf Thanks Danp2 and Water! Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 28, 2017 Author Share Posted August 28, 2017 (edited) To be honest this isn't working. I thought it does because tabs have always been in a control and never in overflowing number. Anyone has an idea why this ain't working? Mozrepl is on. What should I try? Any suggestions? Global Const $_FF_AU3VERSION = "0.6.0.1b-15" Firefox 54.0.1 (32-bit) mozRepl 1121-signed.1-signed by hyperstruct (https://github.com/bard/mozrepl/wiki) Windows 7 ultimate SP1 Edited August 28, 2017 by Fr33b0w Link to comment Share on other sites More sharing options...
Danp2 Posted August 28, 2017 Share Posted August 28, 2017 You'll need to provide more details. What exactly isn't working as you would expect? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 28, 2017 Author Share Posted August 28, 2017 i basically want to limit number of open tabs in firefox so if there is more opened then (lets say) 5, I need to limit them down, as simple as it sounds and as complicated as it is when trying to code it . At this point I am getting "" as an answer no matter how many tabs exist in firefox... $tabs=0 Link to comment Share on other sites More sharing options...
Danp2 Posted August 28, 2017 Share Posted August 28, 2017 It really isn't difficult. You just need to create a loop that will run until the number of tabs is within the desired range, something like this -- While _FFGetLength("tabs") > 5 _FFTabClose('last', 'key') WEnd Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 28, 2017 Author Share Posted August 28, 2017 Thanks for that but it wouldn't give me info how much tabs are open. Do you have a clue why it might be so and what should I try? #Include <FF.au3> While _FFGetLength("tabs") > 5 _FFTabClose('last', 'key') WEnd [Click and drag to move] Link to comment Share on other sites More sharing options...
Danp2 Posted August 28, 2017 Share Posted August 28, 2017 Not off hand. I'll have to dig into the UDF code to try to figure out why it isn't working as designed. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted August 28, 2017 Share Posted August 28, 2017 Ok... there's nothing wrong with the UDF. You have to first establish the connection to FF. So the revised script would be -- #Include <FF.au3> _FFConnect() While _FFGetLength("tabs") > 5 _FFTabClose('last', 'key') WEnd Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Somerset Posted August 29, 2017 Share Posted August 29, 2017 If you click on a tab, and locate in the menu "Close Other Tabs" and click. it will give you a dialog box with the number of tabs. Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 31, 2017 Author Share Posted August 31, 2017 (edited) On 8/29/2017 at 2:23 AM, Somerset said: If you click on a tab, and locate in the menu "Close Other Tabs" and click. it will give you a dialog box with the number of tabs. It won't give me right click menu on tabs on win7. It did before on XP but I guess upgrade or something wont work like that. On 8/28/2017 at 7:52 PM, Danp2 said: Ok... there's nothing wrong with the UDF. You have to first establish the connection to FF. So the revised script would be -- #Include <FF.au3> _FFConnect() While _FFGetLength("tabs") > 5 _FFTabClose('last', 'key') WEnd It did showed me first time or with first run of the script but now it won't show me how much tabs are open... My code: #Include <FF.au3> _FFConnect() Sleep(2000) If _FFIsConnected() Then $tabs=_FFGetLength("tabs") If $tabs > 4 Then ;_FFTabClose("first") _FFTabClose("last") Sleep(1000) ;_FFDisConnect() EndIf EndIf Is there any kind of workaround with this or anyone knows why it won't count tabs? Help again much appreciated. Edited August 31, 2017 by Fr33b0w Link to comment Share on other sites More sharing options...
Danp2 Posted August 31, 2017 Share Posted August 31, 2017 You had a problem in your _FFTabClose line, but otherwise looks fine to me. Try running the following in Scite and post the complete results from the output window -- #Include <FF.au3> _FFConnect() Sleep(2000) If _FFIsConnected() Then $tabs=_FFGetLength("tabs") ConsoleWrite("$tabs=" & $tabs & @CRLF) If $tabs > 4 Then _FFTabClose("last", 'key') EndIf EndIf Fr33b0w 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 31, 2017 Author Share Posted August 31, 2017 Thanks! _FFConnect: OS: WIN_7 WIN32_NT 7601 Service Pack 1 _FFConnect: AutoIt: 3.3.14.2 _FFConnect: FF.au3: 0.6.0.1b-15 _FFConnect: IP: 127.0.0.1 _FFConnect: Port: 4242 _FFConnect: Delay: 2ms _FFConnect: Socket: 536 _FFConnect: Browser: __FFSendJavaScripts: Sending functions to FireFox .......... done __FFSend: try{FFau3 != null?1:0}catch(e){'_FFCmd_Err';}; __FFRecv: _FFIsConnected ==> Socket Error: 536 >Exit code: 0 Time: 3.747 Link to comment Share on other sites More sharing options...
Danp2 Posted August 31, 2017 Share Posted August 31, 2017 Are you sure that you have MozRepl installed and running? Your output should look like this -- _FFConnect: OS: WIN_10 WIN32_NT 15063 _FFConnect: AutoIt: 3.3.14.2 _FFConnect: FF.au3: 0.6.0.2b-1 _FFConnect: IP: 127.0.0.1 _FFConnect: Port: 4242 _FFConnect: Delay: 2ms _FFConnect: Socket: 872 _FFConnect: Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0 __FFSendJavaScripts: Sending functions to FireFox .......... done __FFSend: try{FFau3 != null?1:0}catch(e){'_FFCmd_Err';}; __FFRecv: 1 __FFSend: try{gBrowser.tabContainer.childNodes.length}catch(e){'_FFCmd_Err';}; __FFRecv: 16 $tabs=16 __FFSend: try{gBrowser.tabContainer.childNodes.length}catch(e){'_FFCmd_Err';}; __FFRecv: 16 __FFSend: try{gBrowser.removeTab(gBrowser.mTabs[gBrowser.tabContainer.childNodes.length-1]);gBrowser.tabContainer.childNodes.length}catch(e){'_FFCmd_Err';}; __FFRecv: 15 +>10:50:44 AutoIt3.exe ended.rc:0 +>10:50:44 AutoIt3Wrapper Finished. Also, what version of Firefox are you using? If you are using FF 55 or greater, then MozRepl is no longer working and that would explain your issues. Fr33b0w 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Fr33b0w Posted August 31, 2017 Author Share Posted August 31, 2017 You are right... It upgraded while my son was using the PC. Its 55.0.3 (32-bit) now. Thanks for Your help! Link to comment Share on other sites More sharing options...
junkew Posted August 31, 2017 Share Posted August 31, 2017 (edited) You can use uiautomation. see below faq 31 Edited August 31, 2017 by junkew Fr33b0w 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Fr33b0w Posted September 1, 2017 Author Share Posted September 1, 2017 I have temp solved it with addon for FF (Window and Tab Limiter) because I needed limited tabs to be opened due to FF crash. This uiautomation really looks good so I will check it out. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now