0

I have a problem with WPF browser. i want to load a web page. Wait for it load completely and then put few search inputs and then retrieve the result and put it in excel.

I am unable to do so, main program loads and completes the execution before the pagecomplete_event is loaded. The scenario is:

  1. load a component provider website
  2. go to the search option and search for the part number which I am reading for a EXCEL file
  3. put the part number in the search bar and click search
  4. download the details
  5. repeat the steps for MANY parts

I have done this with WinForms, and it works well. The problem is calling DOEVENTS. It sometimes makes my program hang, especially if operating on a big list. So wanted to do it in WPF.

I have put the Load_Complete event, but as I mentioned, it comes to that event after the main program has finished.

I searched and got this link: How to create and use WebBrowser in background thread. But it doesn't seem to help - there seems to be no System.Windows.Deployment in WPF - I get red squiggly underline. No other solutions that I have found seem to help, either.

Community
  • 1
  • 1
manu vishwanath
  • 97
  • 1
  • 1
  • 14
  • `System.Windows.Deployment` seems to be specific to Silverlight: http://msdn.microsoft.com/en-us/library/system.windows.deployment(v=vs.95).aspx – paddy May 24 '13 at 03:51
  • I can't seem to understand your goal. Do you want the Main UI Thread wait for the task to complete or you wan't to load page in a background thread without blocking the wpf main UI thread? – Jatin May 24 '13 at 04:26
  • my goal is-- Load page in wpf browser.--put searching details--Extract Details from page--Reload the Page with new search details and extract again-- repeat till there are no more search list.... while doing this search the page application must wait till the page is loaded and extract. the application is not waiting for WPF browser to complete loading of the page and trigger page load event where i have extraction code – manu vishwanath May 24 '13 at 04:34

1 Answers1

0

This was troubling me for some time, and finally found the solution. Now I'm fairly new to vb.net so this may not be the best way, but it did work. This is in vb.net, you could probably easily convert to c#.

AddHandler (webbrowser1.LoadCompleted), AddressOf WebpageLoaded
    webbrowser1.Navigate("http://www.myWebsite.net/admin/")

This creates an event that triggers the WebpageLoaded sub.

I used this to wait for the page to load and then login to my account. Here is how I did that.

Private Sub WebpageLoaded()
    If webbrowser1.Url.ToString = "http://www.myWebsite.net/admin/" Then
        webbrowser1.Document.GetElementById("username").ScrollIntoView(True)
        webbrowser1.Document.GetElementById("username").SetAttribute("value", "myUsername")
        webbrowser1.Document.GetElementById("password").SetAttribute("value", "myPassword")
    End If
End Sub

I do hope this helps. You probably don't need to ScrollIntoView I just used this to see the progress as I finally got it to work.

dmshow
  • 121
  • 13