MrMike2000 Posted April 12, 2020 Share Posted April 12, 2020 (edited) I'm trying to make a simple login script to an HTTPS tunneling service and I've hit a bit of a weird snag... The code below opens up Firefox to a given URL and tries to TAB to the first input box (the username). The script opens Firefox up correctly but the new browser window appears in the background, often behind the SciTE editor. The resulting keystrokes get sent to the SciTE editor. I've tried to focus the window with WinActivate but it doesn't seem to find the window. If I start the script by double-clicking on it (as opposed to running it from editor) the browser appears behind the file explorer window. I tried pausing things a bit with some Sleep commands to give Firefox time to start up, but nothing seems to work so far. Basically my questions are: What am I doing wrong- why is the browser appearing behind things instead of on top? How can I open that URL and send keystrokes to the form? #Include <WinAPI.au3> #include <Constants.au3> #include <AutoItConstants.au3> $command = "C:\Program Files\Mozilla Firefox\firefox.exe -new-tab " $url = "https://dashboard.ngrok.com/login" Run($command & $url, "") Sleep(5) WinActivate("ngrok") Sleep(4) ; send 2 tabs Send("{TAB}") Send("{TAB}") Edited April 18, 2020 by MrMike2000 Link to comment Share on other sites More sharing options...
careca Posted April 12, 2020 Share Posted April 12, 2020 Hi, instead of winactivate, i think winwait or winwaitactive would work better #Include <WinAPI.au3> #include <Constants.au3> #include <AutoItConstants.au3> $command = "C:\Program Files\Mozilla Firefox\firefox.exe -new-tab " $url = "https://dashboard.ngrok.com/login" Run($command & $url, "") WinWait("ngrok") WinActivate("ngrok") ; send 2 tabs Send("{TAB}") Send("{TAB}") MrMike2000 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
MrMike2000 Posted April 12, 2020 Author Share Posted April 12, 2020 (edited) Thank you , Careca, that helped. It now brings the Firefox browser up on top of everything and at the right URL, but I'm not seeing it send any keystrokes. After a little work I gave it a few seconds of Sleep after the Winactivate command and that seemed to give it enough time to get ready for input. So as of now, this part works. Thanks for your help Careca! #Include <WinAPI.au3> #include <Constants.au3> #include <AutoItConstants.au3> $command = "C:\Program Files\Mozilla Firefox\firefox.exe -new-tab " $url = "https://dashboard.ngrok.com/login" Run($command & $url, "") WinWait("ngrok") WinActivate("ngrok") Sleep(5000) ; send 2 tabs Send("{TAB}") Send("{TAB}") ; send username Send("none@none.com") Sleep(2000) ; tab to next field Send("{TAB}") ; enter the password and then Send("{Enter}")...etc etc Edited April 13, 2020 by MrMike2000 careca 1 Link to comment Share on other sites More sharing options...
MrMike2000 Posted April 14, 2020 Author Share Posted April 14, 2020 So to follow up, my goal was to log into the ngrok service and (eventually) pull some text off the screen (the current HTTPS tunnels). After login ngrok takes you to your dashboard, which wasn't where I wanted to go (I need to go to the status page). I was going to send some more TABs to get to the link I wanted and then click on it, but that seemed a little shaky- if they change the site the script would break. Unfortunately, the Autoit tool that you can use to hover over something and find out info about it doesn't seem to work on the ngrok site- it doesn't find buttons or text at all. So I went about it another way, albeit probably not the cleanest way, but it works. I use Autoit to login, wait a few moments, and then close the browser. Then I have Autoit open up a new browser window with the URL of the status page, and it goes right to it. Now I have to figure out how to get the text off the screen, so it's time for me to do some more reading. (At the same time, any suggestions would be more than welcome.) Link to comment Share on other sites More sharing options...
Danp2 Posted April 14, 2020 Share Posted April 14, 2020 @MrMike2000 When you are ready to implement a "cleaner" solution, take a look at the Webdriver UDF (see my sig). Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
MrMike2000 Posted April 18, 2020 Author Share Posted April 18, 2020 (edited) Danp2, Thank you; yes, my method is pretty kludgy, no doubt about it. I've seen the Webdriver page and it looks like the way to go; I tried using it but I'm sure I was doing something wrong and I couldn't get to work for me. Maybe I can give it another go. Edited April 18, 2020 by MrMike2000 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