0

Want to use GeckoWebBrowser to simulate mouse clicks

Xpcom.Initialize("Firefox");
geckoWebBrowser1.Navigate("https://www.abc.aaa");
geckoWebBrowser1.Navigate(url);
textBox1.Text = geckoWebBrowser1.Document.Body.OuterHtml;

What to do before you can click to have a effect

<div id="btnA" class="menuA" onclick="ChangeType('A')"></div>

Tried three methods, but they all fail

GeckoWebBrowser1.Document.GetElementsByTagName("div");?
GeckoWebBrowser1.Document.GetElementById("btnA")).Click();    
GeckoWebBrowser1.Document.GetElementById("btnA").SetAttribute("ChangeType","A");

Trouble master guide, thank you

jackie
  • 3
  • 2
  • Why would anyone want to create something that programmatically click on a web site? – Sach Aug 31 '18 at 22:21
  • Hi @jackie, have you considered using pure js to simulate mouse clicks? (https://www.w3schools.com/jsref/met_html_click.asp) You can use the GeckoWebBrowser to run the js (https://stackoverflow.com/questions/17803409/how-can-execute-javascript-commands-via-geckofx) – Ronak Shah Aug 31 '18 at 22:37
  • I tested it, mainly to operate the other's website. So I want to say how to simulate a mouse click. ((GeckoHtmlElement)geckoWebBrowser1.Document.GetElementById("btnSC")).Click(); Thank you for your information. – jackie Sep 01 '18 at 05:24

1 Answers1

1

Hey heres how i would do it with the built in browser so cant be much different also i built bot for helping myself find elements if you wanna check it out http://devbeebee.com/c-browser-element-bot/

void Find_Element()
    {
        string x1 = "<div";
        string x2 = "btnA";

        var ele = ElementBrowser.Document.GetElementsByTagName("div");
        foreach (HtmlElement link in ele)
        {
            string item = link.OuterHtml.ToString().Trim();
            if (item.StartsWith(x1) && item.Contains(x2))
            {
                link.InvokeMember("click");
            }
        }
    }
Devbeebee
  • 11
  • 2