vigo Posted July 10, 2013 Share Posted July 10, 2013 Hello! I am new to AutoIt, and have created my first script for my department at work. One of the functions we do I run a Social Security Number check on all our hires. All this data is stored on a spreadsheet, and I have created a simple script to automate the copying and pasting of the data over to the website. The script will use simple Send commands to: 1) Activate the spreadsheet and Wait until Active 2) Go to the correct cell and copy the data 3) Go to the SSN check website and paste the into the correct text box. 4) Tab to the next text box needed. 5) Repeat for each field needed for each employee, and repeat 10 times since the website allows 10 names to be checked Everything on my script goes swimmingly, but I would say every other time I run it, it screws up and doesn't paste and tab into the web page for one of the text boxes on the 9th or 10th employee line. Then it goes back into the spreadsheet and copies and pastes in the later data into that text box. I am not sure why the paste and tab on the web page doesn't always work, and have tried another computer as well. I use WinWaitActive, and I have also run a sleep command after ward to see if it just needed more time, no luck. Here is the code, Where you see the sleep commands is where the script usually errors out. Thanks for the help. expandcollapse popup; AutoIt Version: 3.0 ; Program Name: SSN ID Check Tool ; Language: English ; Platform: Win7 ; Script Function: ; Automatically enters in ID check information from Spreadsheet into the SSA website. ; Send FEIN and go to home Cell WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("111111111") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") Send("{TAB}") ;*******10 lines of SSA Check begin******* WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Sleep(1000) Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Sleep(1000) Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Sleep(1000) Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{LEFT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("{RIGHT}") Send("^c") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("^v") Send("{TAB}") WinActivate("Microsoft Excel") WinWaitActive("Microsoft Excel") Send("{DOWN}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") ; *******10 lines of SSA Check end******* WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification") Send("{ENTER}") ; *******completed 10 entries Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 10, 2013 Moderators Share Posted July 10, 2013 Hi, vigo, welcome to the forum. To begin with, I would highly suggest you take a look at the _Excel functions in the Help File. You should easily be able to trim 90% of your Send commands, which can be very unreliable. Once you've done that, you should find it much easier to track down where the script is balking. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
vigo Posted July 10, 2013 Author Share Posted July 10, 2013 Thank you for your reply. I see what you mean about the excel functions, I will look into it and work on updating and cleaning my script. I definitely want it as reliable as possible. I do have to say though, I think the issue is not on the excel side, but rather on the web page side. I monitored the clipboard history on excel as the script is running, and everything copies to it as expected. It just seems that when the web brower is activated (internet explorer) the data is not pasting when the command hits. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 11, 2013 Share Posted July 11, 2013 You'll find Internet Explorer functions in the help file as well. Perhaps this will help your script run correctly. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Solution TheSaint Posted July 11, 2013 Solution Share Posted July 11, 2013 (edited) What the others say is correct, but here are some hints to help with your coding. Quite likely there are more instances where you can optimize, but these stood out and I haven't looked any further, because the UDF's would be the better bet mostly. Instead of sending something like Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") Send("{LEFT}") 6 or so times, you can do it more simply as Send("{LEFT 6}") or Send("{TAB 2}") for TABS etc And with your WinWaitActive commands, I would provide a 'Wait' instead of or as well as your 'Sleep' command instances, that way if there is a delay for some reason out of the norm, it can be accommodated. Often '10' seconds is a good enough delay, that will only be used if it needs to be. I would back that up with a If WinActive and Else set of statements, so that you can accommodate any issues. It's never really good to have an open ended WinWaitActive statement. WinWaitActive("Microsoft Excel", "", 10) I would also look into using Handles for your subsequent calls, so that you get better targeting of Program Window Titles. .. That alone may fix your issues, but I would go the route of the UDF's where you can, as they will offer more surety. P.S. Got distracted by a very demanding puppy, so I rushed first time around, and had more to add/edit. Edited July 11, 2013 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
vigo Posted July 11, 2013 Author Share Posted July 11, 2013 (edited) Well, I have to say thank you for the help cleaning up my script. I followed your advice, and it runs faster and errors out much less. I also put most of the send commands on a loop with a few IF statements for the variations I needed to put in on the first and last line. Things are running a bit better. It does still occasionally error out, and while it is minimal enough that I can live with it, I think I found a method that should solve the problem, I just need to test it further. An error box pops up in internet explorer when the wrong type of data is entered. It is always the same box that errors out. I just put in an If WinExists statement to look for this box at the right point in the script. If the box is there, I tell it to hit OK and then delete the data and start over with the problem data. If WinExists("Message from webpage") Then WinActivate("Message from webpage") ControlClick("Message from webpage", "", "Button1", "left") WinActivate("BSO - SSN Verification") WinWaitActive("BSO - SSN Verification", "", 10) Send("{BACKSPACE 11}") ;delete junk data ; the commands that need to be repeated go here. EndIf Edited July 11, 2013 by vigo 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