3

I'm using Awesomium in C# winforms app to click on a div inside the webpage.

the following script works just fine if you type it directly in google chrome:

javascript: document.getElementById('ac_play').click();

but when I try to execute it in awesomium using either:

webControl1.ExecuteJavascript("document.getElementById('ac_play').click();");

or this:

webControl1.LoadURL("javascript: document.getElementById('ac_play').click();");

It's not working. Which makes me think - does Awesomium support "div clicks" or not? Or maybe there is another reason why it's not working?

I've also tried to execute the code:

  • on LoadCompleted event (to make sure that the page is loaded completely)
  • by typing the script manually in "addressBox1" (native awesomium "address bar" control)

As usual - nothing is working.

EDIT:

I've tested the same javascript in GeckoFX and it's not working there either.. Any workaround?

EDIT2

Standart WebBrowser control executes the script perfectly! (Although it's using IE5 or so.. that's why I'd like to see Awesomium solution working).

P.S. it was working in webcontrol and now it's not ;( how do i reset it? P.P.S. i removed the cache in IE but it's sooo unreliable to use standard WebBrowser..

Alex
  • 4,607
  • 9
  • 61
  • 99
  • what version of geckofx/firefox did you try? – Tom Aug 27 '12 at 23:18
  • Have you tried upgrading to the latest [Awesomium 1.7 RC](http://awesomium.com/download/)? The API changes significantly, but it may solve your issue. Version 1.7 allows you to manipulate the DOM and access HTML DOM objects. Provided you use 1.7, I could give you an alternative example of how to do this. – Perikles C. Stephanidis Feb 03 '13 at 09:28
  • just tried 1.7RC3 - it can't access HTML DOM, nor it does any operations with HTML elements except executing javascript. It doesn't even support as simple operation as saving page's HTML to string... http://stackoverflow.com/questions/14761334/interacting-with-awesominum-webcontrol/14761555#comment20662646_14761555 – Alex Feb 08 '13 at 08:39
  • DIV click doesn't work either – Alex Feb 08 '13 at 11:50
  • goto "vk.com" -> goto "music" -> try clicking on div with id "ac_play" using awesomium – Alex Feb 08 '13 at 12:07

2 Answers2

1

Remember that you have to wait for DocumentReady event with DocumentReadyState as Loaded (not Ready - because then Awesomium is not quite ready yet)

private void WebControl_DocumentReady(object sender, DocumentReadyEventArgs e)
{
    if (e.ReadyState != DocumentReadyState.Loaded) return;
    //Here ExecuteJavascript should work
}
voytek
  • 2,202
  • 3
  • 28
  • 44
0
public void JsFireEvent(string getElementQuery, string eventName)
{
    webControl1.ExecuteJavascript(@"
                        function fireEvent(element,event) {
                            var evt = document.createEvent('HTMLEvents');
                            evt.initEvent(event, true, true ); // event type,bubbling,cancelable
                            element.dispatchEvent(evt);                                 
                        }
                        " + String.Format("fireEvent({0}, '{1}');", getElementQuery, eventName));
}

JsFireEvent("document.getElementById('ac_play')", "click");

Link

mazanuj
  • 1
  • 3