WatIn的右键方法?

发布于 2024-10-29 02:50:41 字数 71 浏览 2 评论 0原文

我试图右键单击树节点,但找不到该类的 Rightclick 方法。 Watin 是否具有右键单击操作功能?

谢谢

I am trying to right click on a tree node but can't find the Rightclick method of the class. Does Watin feature a right click action?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

王权女流氓 2024-11-05 02:50:41

不,您需要触发一个事件。如果只是 Internet Explorer,那么很容易传递所需的按钮值 2,即

    NameValueCollection eventProperties = new NameValueCollection(); 
    eventProperties.Add("button", "2"); 
    yourElement.FireEvent("onmousedown", eventProperties);

如果您正在使用 FireFox,那么事情就没那么简单了,您可以阅读我的 较旧的问题,WatiN 开发人员友善地回复了。正如他在其他地方指出的那样,这应该在 WatiN 内。

同样的方法可以让您在 FireFox 中进行拖放。

No, you need to fire an event. If it's just Internet Explorer then it's easy to pass the required button value of 2, i.e.

    NameValueCollection eventProperties = new NameValueCollection(); 
    eventProperties.Add("button", "2"); 
    yourElement.FireEvent("onmousedown", eventProperties);

If you are working with FireFox then it is not so simple, you can read my older question to which the WatiN developer kindly responded. As he notes elsewhere this should be within WatiN.

The same approach will let you drag and drop within FireFox.

自演自醉 2024-11-05 02:50:41

您可以尝试:

myElement.FireEvent("oncontextmenu")

它将启动JavaScript事件,该事件将打开“元素上下文”菜单,这通常是当您右键单击元素时发生的情况。它在 Internet Explorer 中对我有用,但我还没有在 FireFox 中测试过它。

You could try:

myElement.FireEvent("oncontextmenu")

It will fire the JavaScript event that will open the elements context menu, which is what normally happens when you right click an element. It's worked for me in Internet Explorer, but I haven't tested it in FireFox.

陌伤ぢ 2024-11-05 02:50:41

Jen 就在这里(你应该接受她的回答)。

树节点上的 FireEvent("oncontextmenu") 对我来说也不起作用,直到我找到存在事件的元素。

节点通常是 Div 控件,我是这样实现的:

// Selecting node span first
myDiv.Spans[0].Click();
// Firing the event on the Div
myDiv.FireEvent("oncontextmenu");

树节点(以及所有其他复杂的 DOM 结构)的主要问题是在正确的 DOM 元素上触发事件。

在大多数复杂的 DOM 结构中,事件在控件的 Init() 期间由 JavaScript 代码附加(例如 Telerik 就是这样做的)。因此您无法在 HTML 源代码中看到该事件。

如果找不到事件,则必须使用 Visual Studio 等来调试 javascript。

为了理解我在说什么,这里有一个关于如何使用 JavaScript 附加事件的示例:

TreeView.prototype.OnInit=function(){
this.AttachAllEvents();
}

TreeView.prototype.AttachAllEvents=function(){
var _this=this;
var _container=document.getElementById(this.Container);
_container.onfocus=function(e){
eventDispatcher(_this.ClientID,"focus",e);
};
_container.onmouseover=function(e){
eventDispatcher(_this.ClientID,"mouseover",e);
};
_container.onmouseout=function(e){
eventDispatcher(_this.ClientID,"mouseoout",e);
};
_container.oncontextmenu=function(e){
eventDispatcher(_this.ClientID,"contextmenu",e);
};
_container.onclick=function(e){
eventDispatcher(_this.ClientID,"click",e);
};
_container.ondblclick=function(e){
eventDispatcher(_this.ClientID,"doubleclick",e);
};
_container.onkeydown=function(e){
eventDispatcher(_this.ClientID,"keydown",e);
};
if(window.attachEvent){
window.attachEvent("onunload",function(){
_this.Dispose();
});
}
};

Jen is right here (you should accept her answer).

FireEvent("oncontextmenu") on a Tree Node didn't work for me either until I found the element where the event was present.

Nodes are usually Div controls and I achieve it like this :

// Selecting node span first
myDiv.Spans[0].Click();
// Firing the event on the Div
myDiv.FireEvent("oncontextmenu");

The main problem of the Tree Nodes (and all other complex DOM structure) is to fire the events on the good DOM element.

In most complex DOM structures, the events are attached by JavaScript code during the Init() of the controls (Telerik does it for example). So you can't see the event in the HTML source.

If you can't find the events, you'll have to debug your javascript using Visual Studio for example.

To understand what I'am speaking about, here is an example on how events could be attached with JavaScript :

TreeView.prototype.OnInit=function(){
this.AttachAllEvents();
}

TreeView.prototype.AttachAllEvents=function(){
var _this=this;
var _container=document.getElementById(this.Container);
_container.onfocus=function(e){
eventDispatcher(_this.ClientID,"focus",e);
};
_container.onmouseover=function(e){
eventDispatcher(_this.ClientID,"mouseover",e);
};
_container.onmouseout=function(e){
eventDispatcher(_this.ClientID,"mouseoout",e);
};
_container.oncontextmenu=function(e){
eventDispatcher(_this.ClientID,"contextmenu",e);
};
_container.onclick=function(e){
eventDispatcher(_this.ClientID,"click",e);
};
_container.ondblclick=function(e){
eventDispatcher(_this.ClientID,"doubleclick",e);
};
_container.onkeydown=function(e){
eventDispatcher(_this.ClientID,"keydown",e);
};
if(window.attachEvent){
window.attachEvent("onunload",function(){
_this.Dispose();
});
}
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文