1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# WebBrowser mouse cursor

Discussion in 'C, C++, C#' started by Dan2009, Mar 2, 2011.

  1. Dan2009

    Dan2009 Junior Member

    Joined:
    Jun 5, 2009
    Messages:
    133
    Likes Received:
    73
    I have a WebBrowser Control which loads up a webpage. Does anyone know how I can make my mouse cursor move over specific text on the page?

    For example if I have a link with the anchor text "Click Here"
    How can I make it so my mouse cursor hovers over the "Click Here" text?

    any help would be greatly appreciated :)
     
  2. theMagicNumber

    theMagicNumber Regular Member

    Joined:
    May 13, 2010
    Messages:
    345
    Likes Received:
    195
    Hello, try this:

    Code:
    HtmlElement elem = testWebBrowser.Document.Links.OfType<HtmlElement>().FirstOrDefault(p => p.InnerText == "Click Here");
    if(elem != null)
    {
         int centerX = elem.OffsetRectangle.X + elem.OffsetRectangle.Width / 2;
         int centerY = elem.OffsetRectangle.Y + elem.OffsetRectangle.Height / 2;
         Cursor.Position = this.testWebBrowser.PointToScreen(new Point(centerX, centerY));
    }
    
    It will position the cursor at the first link with anchor text "Click Here".
     
    • Thanks Thanks x 2
    Last edited: Mar 3, 2011
  3. reinrein

    reinrein Regular Member

    Joined:
    Feb 8, 2008
    Messages:
    443
    Likes Received:
    343
    Home Page:
    just invoke the click instead of making the mouse go to that area I think?
    webbrowser.getelementbyid("idname").invoke("click")
    something like that.
     
    • Thanks Thanks x 1