?
Solved

c#- SendKeys.Send("{tab}") to Internet explorer

Posted on 2011-03-16
5
Medium Priority
?
2,903 Views
Last Modified: 2012-05-11
HI,

I have created a simple winform application to launch the browser on a click of the button. The code is as follows:

        private void button1_Click(object sender, EventArgs e)
        {
           Process IEProc = new Process();
           IEProc.StartInfo.FileName = "iexplore.exe";
           IEProc.StartInfo.Arguments = "http://google.com";
           IEProc.Start();
           //IEProc.StandardInput.Write("Hello World");
           
           SendKeys.Send("{tab}");
        }

The purpose of putting the line "SendKeys.Send("{tab}");" is to navigate to the new field on google.com. However, the tabbing is happening on winform application. Can someone please let me know how the tab can be used on google.com.

Appreciate your help.


0
Comment
Question by:deoyagya
5 Comments
 
LVL 10

Expert Comment

by:John Claes
ID: 35145921
When opening the iexplore you should just wait for a few moments before sending the TAB.
Why?

the iexplore is still opening when the TAB is send, and your winform is still in front. ;-)

waiting :
using System.Threading;


Thread.Sleep(10 * 1000); // 10 Seconds delay


regards

poor beggar
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35145928
try this

      IEProc.Start();
                  IEProc.WaitForInputIdle();

                  SendKeys.Send("{tab}");
0
 
LVL 4

Accepted Solution

by:
parnasso earned 1200 total points
ID: 35146016
In order to implement the SendKeys function, you need to finde the internet explorer window that receives the user input and send an WM_KEY... message to it. I'm not sure if your approach is going to give you more problems than you think.

I would suggest to add a reference to the internet explorer interface through COM (automation). If you are not familiar with automation, take a look at this project:

Internet explorer automation
0
 
LVL 12

Assisted Solution

by:FarWest
FarWest earned 800 total points
ID: 35146512
you can get the process window handle, and the setfoucs to that window, before sending keys
check this, http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx


and pay attention to this note in the page
"If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, an exception will be thrown."


good luck
0
 

Author Closing Comment

by:deoyagya
ID: 35275429
Thanks for the assistance.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question