本文介绍了在 awesomium 中执行 javascript 以单击 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# winforms 应用程序中使用 Awesomium 单击网页内的 div.

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

如果您直接在 google chrome 中输入以下脚本,它就可以正常工作:

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

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

但是当我尝试使用以下任一方法在 awesomium 中执行它时:

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

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

或者这个:

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

它不起作用.这让我想到 - Awesomium 是否支持div 点击"?或者也许还有其他原因导致它不起作用?

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?

我也尝试过执行代码:

  • 关于 LoadCompleted 事件(以确保页面完全加载)
  • 在addressBox1"(原生 awesomium地址栏"控件)中手动输入脚本

像往常一样 - 没有任何效果.

As usual - nothing is working.

我在 GeckoFX 中测试了相同的 javascript,但它也无法在那里工作.. 有什么解决方法吗?

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

EDIT2

Standart WebBrowser 控件完美执行脚本!(虽然它使用的是 IE5 左右......这就是为什么我希望看到 Awesomium 解决方案工作).

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).

附言它在 webcontrol 中工作,现在不是;(我如何重置它?P.P.S.我删除了 IE 中的缓存,但使用标准 WebBrowser 太不可靠了..

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..

推荐答案

记住,你必须等待 DocumentReady 事件,DocumentReadyStateLoaded> (不是 Ready - 因为那时 Awesomium 还没有完全准备好)

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
}

这篇关于在 awesomium 中执行 javascript 以单击 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 22:47