2

I am trying to let click/write on the Awesomium WebControl, but it doesn't work. This is the code that I use:

WebControl1.Source = New Uri("website") 'i dont put the website
xpath=link.xpath
Dim nlink As JSObject = WebControl1.ExecuteJavascriptWithResult([String].Format("document.evaluate(""{0}"", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue", xpath))

nlink.InvokeAsync("click")
end if
next
Opal
  • 81,889
  • 28
  • 189
  • 210
dijamenh
  • 21
  • 4

1 Answers1

1

If you want to just trigger 'click' on your website content, that should work (using jQuery):

WebControl1.ExecuteJavascript(@"$(document.body).trigger('click');");

or (I've found it here, not tested):

        dynamic document = (JSObject)webView.ExecuteJavascriptWithResult("document");

        if (document == null)
            return;

        using (document)
        {
            dynamic signin = document.getElementById("signin");

            if (signin == null)
                return;

            using (signin)
                signin.click();
        }

Remember to wait till DocumentReady is Loaded state:

    private void BaseWebControl_DocumentReady(object sender, DocumentReadyEventArgs e)
    {
        if (e.ReadyState != DocumentReadyState.Loaded) return;

        // Now! 
    }

EDIT:

<a id="foo" href="http://...." target="_blank">Test link</a>

in jQuery:

jQuery('#foo')[0].click();
voytek
  • 2,202
  • 3
  • 28
  • 44
  • Thanks, I'm trying, but I would write to the webcontrol1, too – dijamenh Jun 05 '15 at 14:46
  • I would to click with an ID on page, what shoud i do? – dijamenh Jun 05 '15 at 14:47
  • Do you want to simulate `click` on specific DOM object? @dijamenh – voytek Jun 05 '15 at 14:57
  • @dijamenh I added EDIT to my answer – voytek Jun 05 '15 at 15:00
  • I must click by coordinates X,Y and write to the document, is it possible? – dijamenh Jun 05 '15 at 15:11
  • Sorry, but I'm not sure I understand you. What is " to write too on the document"? I just showed you how to run script via Awesomium, you can use jQuery. I showed you how to simulate click on DOM object. [Here](http://stackoverflow.com/questions/2845178/triggering-a-javascript-click-event-at-specific-coordinates) you can find how to click on X,Y coordinates. – voytek Jun 05 '15 at 15:19
  • Sorry but I would make it on vb.net, a solution? Btw, I have a flash game, with childforms that are made in run-time and runned in run-time, I would click on the center of the screen of awesomium and write from the textbox1. Should I use sendkeys.send? – dijamenh Jun 05 '15 at 15:23
  • I think you got the idea reading c#. For more information read [this](http://wiki.awesomium.net) carefully. If you have other question, ask new, separate one – voytek Jun 05 '15 at 15:35
  • On my question i said "and how to write on the document? should i use sendkeys?". – dijamenh Jun 05 '15 at 15:38
  • @dijamenh I don't know that. I'm not even sure what do you mean by "write on the document". But have you tried yourself? – voytek Jun 05 '15 at 15:52
  • No, I would do that but I add childforms, that contains each awesomium webcontrol, by memory, in run-time, so i don't even know how to manage them. – dijamenh Jun 05 '15 at 15:54
  • 1
    You have to read awesomium tutorial, docs, something, because I can't show you how to manage app build on awesomium webcontrols here. It will be much easier for you then. I hope I helped you at least with trigger 'click' – voytek Jun 05 '15 at 16:02