IE Automation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel B. Harwood

    IE Automation

    Using C# Standard Edition 2003 (a bargain!), I have
    written a multi-threaded Windows forms application which
    checks Web sites of interest for newly posted Web pages.
    On detecting a new page it announces it using the Speech
    API (mini tutorial on speech at bottom).

    I opted to check each Web site with a separate worker
    thread to prevent slow sites from bringing the whole
    process to a grinding halt.

    Unfortunately I appear to have hit a brick wall when it
    comes to sites with frames as the InternetExplore r object
    does not appear to support the IHTMLDocument2: :frames
    interface.

    Despite extensive searching on MSDN and Google I can find
    nothing on this. Can anyone confirm my finding above and
    possibly offer a workaround?

    I have found that if I embed a "Microsoft Web Browser"
    control on the windows form, I can access the frames
    interface. I suppose I could create multiple browser
    controls at run-time, but...

    Cheers,

    Daniel.

    Mini Tutorial - How to use the Speech API (SAPI) to say
    something:

    1. Add a reference to the "Microsoft Speech Object
    Library" COM object to your project.

    2. Add the following using statement to your code:
    using SpeechLib;

    3. Use the following code to say something (keep it
    clean!):

    SpeechVoiceSpea kFlags SpFlags =
    SpeechVoiceSpea kFlags.SVSFlags Async;
    SpVoice speech = new SpVoice();
    speech.Speak("H i there", SpFlags);

  • Tobin Harris

    #2
    Re: IE Automation

    "Daniel B. Harwood" <anonymous@disc ussions.microso ft.com> wrote in message
    news:012d01c39a 4d$30dff9d0$a30 1280a@phx.gbl.. .[color=blue]
    > I opted to check each Web site with a separate worker
    > thread to prevent slow sites from bringing the whole
    > process to a grinding halt.
    >
    > Unfortunately I appear to have hit a brick wall when it
    > comes to sites with frames as the InternetExplore r object
    > does not appear to support the IHTMLDocument2: :frames
    > interface.
    > Despite extensive searching on MSDN and Google I can find
    > nothing on this. Can anyone confirm my finding above and
    > possibly offer a workaround?
    >[/color]

    Accessing frames from the exposed IE COM API is tricky, but I found that
    there is a reliable way of doing it 3 years ago in VB, which *should* work
    for the .NET interop. Hopefully this will give some pointers!...

    Firstly, look trap the NavigateComplet e2 event for the IE instance. This
    will be fired for *each frame* on a multi-frame document (including the page
    that constructs the frameset).

    An argument to this event should be something called pDisp, of type Object.
    You should be able to cast this to an IE Window, and it should have a
    Document property - which is the HTMLDocument (or IHTMLDocument2) or the
    frame. At this point you now should now have a reference to each frame in
    the multi-frame page to do whatever you want with!

    One thing to remember: at this point the page will not have loaded, so
    accessing contents may not work. You'll want to use the DocumentComplet e
    event to trigger the analysis of the page.

    [color=blue]
    > I have found that if I embed a "Microsoft Web Browser"
    > control on the windows form, I can access the frames
    > interface. I suppose I could create multiple browser
    > controls at run-time, but...[/color]

    One problem I had with using the Frames collection was security exceptions
    if the frames were from multiple URLs. Is this still an issue?

    The speechlib intro is useful, I had no idea it was so simple - thanks!

    HTH

    Tobin Harris

    P.S - in case you're interested, I learnt a bit about this IE stuff when
    writing a utility that detected and hooked into running instances of IE. It
    logged every visit to all URLs, including those with framesets, and recorded
    the users activities such as scrolling, searching etc, visit time etc. This
    data was consumed by an intelligent agent which would help the user by
    determining their browsing intent and adjusting their experience
    accordingly. Gotta love that CS degree!



    Comment

    • Guest's Avatar

      #3
      Re: IE Automation

      For my app. trapping just the DocumentComplet e event was
      the answer, where as you described, I can cast the pDisp
      parameter as IWebBrowser2 and retrieve the IHTMLDocument2
      interface for each frame.

      Cheers,

      Daniel H.
      [color=blue]
      >-----Original Message-----
      >"Daniel B. Harwood"[/color]
      <anonymous@disc ussions.microso ft.com> wrote in message[color=blue]
      >news:012d01c39 a4d$30dff9d0$a3 01280a@phx.gbl. ..[color=green]
      >> I opted to check each Web site with a separate worker
      >> thread to prevent slow sites from bringing the whole
      >> process to a grinding halt.
      >>
      >> Unfortunately I appear to have hit a brick wall when it
      >> comes to sites with frames as the InternetExplore r[/color][/color]
      object[color=blue][color=green]
      >> does not appear to support the IHTMLDocument2: :frames
      >> interface.
      >> Despite extensive searching on MSDN and Google I can[/color][/color]
      find[color=blue][color=green]
      >> nothing on this. Can anyone confirm my finding above[/color][/color]
      and[color=blue][color=green]
      >> possibly offer a workaround?
      >>[/color]
      >
      >Accessing frames from the exposed IE COM API is tricky,[/color]
      but I found that[color=blue]
      >there is a reliable way of doing it 3 years ago in VB,[/color]
      which *should* work[color=blue]
      >for the .NET interop. Hopefully this will give some[/color]
      pointers!...[color=blue]
      >
      >Firstly, look trap the NavigateComplet e2 event for the[/color]
      IE instance. This[color=blue]
      >will be fired for *each frame* on a multi-frame document[/color]
      (including the page[color=blue]
      >that constructs the frameset).
      >
      >An argument to this event should be something called[/color]
      pDisp, of type Object.[color=blue]
      >You should be able to cast this to an IE Window, and it[/color]
      should have a[color=blue]
      >Document property - which is the HTMLDocument (or[/color]
      IHTMLDocument2) or the[color=blue]
      >frame. At this point you now should now have a reference[/color]
      to each frame in[color=blue]
      >the multi-frame page to do whatever you want with!
      >
      >One thing to remember: at this point the page will not[/color]
      have loaded, so[color=blue]
      >accessing contents may not work. You'll want to use the[/color]
      DocumentComplet e[color=blue]
      >event to trigger the analysis of the page.
      >
      >[color=green]
      >> I have found that if I embed a "Microsoft Web Browser"
      >> control on the windows form, I can access the frames
      >> interface. I suppose I could create multiple browser
      >> controls at run-time, but...[/color]
      >
      >One problem I had with using the Frames collection was[/color]
      security exceptions[color=blue]
      >if the frames were from multiple URLs. Is this still an[/color]
      issue?[color=blue]
      >
      >The speechlib intro is useful, I had no idea it was so[/color]
      simple - thanks![color=blue]
      >
      >HTH
      >
      >Tobin Harris
      >
      >P.S - in case you're interested, I learnt a bit about[/color]
      this IE stuff when[color=blue]
      >writing a utility that detected and hooked into running[/color]
      instances of IE. It[color=blue]
      >logged every visit to all URLs, including those with[/color]
      framesets, and recorded[color=blue]
      >the users activities such as scrolling, searching etc,[/color]
      visit time etc. This[color=blue]
      >data was consumed by an intelligent agent which would[/color]
      help the user by[color=blue]
      >determining their browsing intent and adjusting their[/color]
      experience[color=blue]
      >accordingly. Gotta love that CS degree!
      >
      >
      >
      >.
      >[/color]

      Comment

      Working...