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
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
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.
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.
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();
});
}
};