【问题标题】:WatiN FireEvent not passing event properties in FireFoxWatiN FireEvent 未在 FireFox 中传递事件属性
【发布时间】:2011-06-26 19:53:43
【问题描述】:

以前是logged as a bug in sourceforge,但现在已删除。

我正在使用带有关联 jssh 的 FireFox 3.6。

我可以在 Firebug 中看到未设置事件属性。我正在尝试使用下面的代码进行拖放

var mouseDownEvent = new NameValueCollection 
                         {{"button", "1"}, {"clientX", "0"}, {"clientY", "0"}};
firstStoryRow.FireEventNoWait("onmousedown", mouseDownEvent);

workarounds 用于传递这些属性,但不是它们不好。

有谁知道这是 WatiN 内部的真正限制还是我做错了什么?

【问题讨论】:

    标签: c# firefox drag-and-drop mouseevent watin


    【解决方案1】:

    这确实是 FireFox 实现的一个缺点。对于鼠标事件,所有给定的参数/值都将被忽略。这应该是固定的,并不难。我将在 SourceForge 上重新打开该问题。

    为了完成这项工作,您可以运行这段代码,这正是 WatiN 实际为您做的事情:

    var jscriptref = firstStoryRow.GetJavascriptElementReference();
    
    var fireeventcode = string.Format("var event = {0}.ownerDocument.createEvent('MouseEvents');",jscriptref);
    
    // Params for the initMouseEvent:
    // 'type', bubbles, cancelable, windowObject, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget )
    fireeventcode += "event.initMouseEvent('mousedown', true, true, null, 0, 0, 0, 0, 0, false, false, false, false, 1, null);";
    fireeventcode += string.Format("var res = {0}.dispatchEvent(event);", jscriptref);
    fireeventcode += "if(res){true;}else{false;};";
    
    // make it a NoWait call by wrapping it in a timer call.
    fireeventcode = JSUtils.WrapCommandInTimer(fireeventcode);
    
    var result = browser.Eval(fireeventcode);
    

    如果结果 == 'true' 一切顺利。 希望这对现在有所帮助,但这需要在下一个版本中修复。

    杰伦

    【讨论】:

    • 这是一种享受,尽管结果是一个数字(假设这是因为我们没有像 WatiN 那样调用 ClientPort.WriteAndReadAsBool(command))。另一方面,可能会变成单独的问题,但是您是否知道在 FireFox 中使用 GetAttributeValue 读取 Dom 属性的任何限制。我正在查看源代码,只看到访问诸如 offset 和 clientWidth 之类的 IE 特定测试。
    • 此(= 原始)问题已在开发代码中修复。将成为下一个 WatiN 2.0+ 版本的一部分。关于FF限制。我必须平衡从 DOM 元素中读取属性值和属性值。可能这就是让你想知道的原因。
    猜你喜欢
    • 2021-02-04
    • 2020-11-17
    • 2012-12-03
    • 2011-12-01
    • 2017-09-10
    • 2019-02-16
    • 2012-05-03
    • 2011-10-21
    • 1970-01-01
    相关资源
    最近更新 更多