By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

Get Focus to window using VB script and SendKeys

P: 3
Hello Experts,
I am working on automating a login to a webpage using SendKeys. The problem I am having is that I am trying to figure out how to get the Internet window in Focus so that way it can run the commands and not keep looping. My code is below:

Thanks,
Steve

Expand|Select|Wrap|Line Numbers
  1. Set IE = CreateObject("InternetExplorer.Application") 
  2. set WshShell = WScript.CreateObject("WScript.Shell")
  3. IE.Navigate "http://www.WebsiteName.com"
  4. IE.Visible = True
  5. Wscript.Sleep 6000 
  6. IE.Document.All.Item("email").Value = "UserName" 
  7. IE.Document.All.Item("pass").Value = "Password"
  8. WshShell.SendKeys "{TAB}"
  9. WshShell.SendKeys "{TAB}"  
  10. WshShell.SendKeys "{ENTER}"
Oct 12 '12 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,382
What is the tab tab enter for? Is that to submit the form? You can use IE.Document.forms(0).submit() where 0 is the index of the form. In this case, it will submit the first form. If it's not the first form, you'll just have to find the correct index.
Oct 12 '12 #2

P: 3
The tab tab enter was to submit the information to the webpage and login. It took two tabs from the password field to login.btn so thats why they were in there.
Oct 13 '12 #3

Rabbit
Expert Mod 10K+
P: 12,382
Yeah, you don't need to do that. You can just use the method in my post instead. It's more reliable.
Oct 13 '12 #4

P: 3
Ok great. Thank you for your help.
Oct 13 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.