Solved

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

Posted on 2011-03-16
5
2,681 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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 200 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
abstract class C# 1 38
C# Linq - Join two objects into one 3 35
Selenium and Xpath 4 32
c# ftp code 3 31
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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