5 Replies - 8452 Views - Last Post: 10 July 2009 - 12:37 AM Rate Topic: -----

#1 mary21clare  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-June 09

Sendkeys problem in Internet Explorer

Posted 08 July 2009 - 11:04 AM

First, I launch a website in Internet Explorer from VB.net and automatically login the user with ther username and password. As soon as the username and password fields are automated, I send "enter" to the website so it goes to the next website. This part works perfectly. However, my problem is that i want to send a mouse click event, which i have already written, to click a hyperlink on the next website page. I tried a few different things, none of which worked. My program is automatically logging in the user and doing the mouse click event at the same time. I have tried to use the "sleep" command, but the mouse click event is still not executing after the second webpage loads. I have tried using nesting "If, then" statements and that has not worked either. Does anyone know how to make sure the webpage fully loads before executing a sendkeys routine or a mouse click event? This is my code thus far:

If (Search.ComboBox1.Text = "IWR") Then
			BlockInput(True)	'this disables the mouse and keyboard

			Dim IE As New Object
			IE = CreateObject("InternetExplorer.Application")
			IE.Navigate("http://SECUREWEBSITE")
			IE.Left = 0
			IE.Top = 0
			IE.TheaterMode = True
			Dim iHeight = IE.Height
			Dim iWidth = IE.Width
			IE.TheaterMode = False
			IE.Height = iHeight
			IE.Width = iWidth
			IE.Visible = True

			Do While IE.Busy
			Loop

			System.Threading.Thread.Sleep(2000)

			System.Windows.Forms.SendKeys.Send(login)
			System.Windows.Forms.SendKeys.Send("{TAB}")
			System.Windows.Forms.SendKeys.Send(password)
			System.Windows.Forms.SendKeys.Send("{ENTER}")

			Do While IE.Busy
			Loop

			System.Threading.Thread.Sleep(2000)

			Windows.Forms.Cursor.Position = New System.Drawing.Point(820, 210)	  'makes the cursor go to a certain position on the monitor display

			Mouse_Down()			'mouse click event
			Mouse_Up()				'mouse click event
		End If





There are no errors, everything is just executing all at once instead of letting the second webpage load and then executing the mouse click event.

Is This A Good Question/Topic? 0
  • +

Replies To: Sendkeys problem in Internet Explorer

#2 quatz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 06-July 09

Re: Sendkeys problem in Internet Explorer

Posted 09 July 2009 - 12:49 AM

may i suggust adding
 System.Threading.Thread.Sleep(100)


between the mouse down and mouse up events

hope that helps
Was This Post Helpful? 0
  • +
  • -

#3 mishipal  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 04-May 09

Re: Sendkeys problem in Internet Explorer

Posted 09 July 2009 - 01:49 AM

This will work .... calling click event after page loads completely
 Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
if WebBrowser1.document.Url.AbsoluteUri = "Desired Web Address"	then
Mouse_Down()			'mouse click event
Mouse_Up()				'mouse click event
END IF
End Sub


Was This Post Helpful? 0
  • +
  • -

#4 mary21clare  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-June 09

Re: Sendkeys problem in Internet Explorer

Posted 09 July 2009 - 05:53 AM

View Postmishipal, on 9 Jul, 2009 - 12:49 AM, said:

This will work .... calling click event after page loads completely
 Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
if WebBrowser1.document.Url.AbsoluteUri = "Desired Web Address"	then
Mouse_Down()			'mouse click event
Mouse_Up()				'mouse click event
END IF
End Sub




Thanks for the replies. Putting the sleep command in between the mouse_down and mouse_up events did not help delay the mouse click event.

Also, when I tried putting in the code that Mishipal suggested, I received an error: "Handles Clause requires a WithEvents variable defined in the containing type or one of its base types"

I tried changing the WebBrowser1 to IE which is what I have defined but still no dice.

How can i make this code snippet work and where do i call the routine in my code?
Was This Post Helpful? 0
  • +
  • -

#5 mary21clare  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-June 09

Re: Sendkeys problem in Internet Explorer

Posted 09 July 2009 - 06:09 AM

Plus, my website never changes. It uses Frames. The URL is continuously the same. I don't think that code will work then :(
Was This Post Helpful? 0
  • +
  • -

#6 mishipal  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 04-May 09

Re: Sendkeys problem in Internet Explorer

Posted 10 July 2009 - 12:37 AM

Then you can check the if the desired element is present and then use the code....

Which line are you getting the error...?

What does mouseup and mousedown subs do...?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1