View Full Version : How to set button id?

29 Dec 2010, 9:55 PM
Hi all,

As we know that when we do a:
Button myBtn = new Button();

This is equivalent to putting id into the outer element with is table instead of button element.
E.g. <table id="MyId" .../> and nothing on <button ... />

I saw a lot of forum here and there, they all having the same problem especially when dealing with selenium test. Is there the best way to put an Id into the button element? or is there the best way to fix in selenium purposes?

Please advice,
Thank you.

29 Dec 2010, 10:45 PM
Here is a small override I made for my Selenium testing team. It's not adding id but if U specify name property in button config it will be added to button element so U can locate it that way

Ext.override(Ext.Button, {
initButtonEl: function(btn, btnEl){
this.el = btn;
if (Ext.isDefined(this.tabIndex)) {
btnEl.dom.tabIndex = this.tabIndex;
//added lines - name property for support Selenium tests
if (this.name) {
btnEl.dom.name = this.name;
//end added lines
if (this.tooltip) {
this.setTooltip(this.tooltip, true);

if (this.handleMouseEvents) {
this.mon(btn, {
scope: this,
mouseover: this.onMouseOver,
mousedown: this.onMouseDown

// new functionality for monitoring on the document level
//this.mon(btn, 'mouseout', this.onMouseOut, this);

if (this.menu) {
this.mon(this.menu, {
scope: this,
show: this.onMenuShow,
hide: this.onMenuHide

if (this.repeat) {
var repeater = new Ext.util.ClickRepeater(btn, Ext.isObject(this.repeat) ? this.repeat : {});
this.mon(repeater, 'click', this.onClick, this);
this.mon(btn, this.clickEvent, this.onClick, this);

hope this helps

30 Dec 2010, 12:01 AM
Thanks for the reply.

May I know how to do it in Java class instead of in javascript?

I tried:

DOM.setElementProperty(myBtn.getElement(), "name", "something123");

Still cannot.


30 Dec 2010, 12:18 AM
I also tried:

El el = new El(myBtn.getElement());
el.dom.setAttribute("name", "SSSSSLL");

This only gave the element table name but not the button name.

30 Dec 2010, 12:29 AM
That's the wrong element.

You want:

myBtn.btnEl.set({name: 'SSSSSLL'});

(but I don't know how to do this in GXT)

30 Dec 2010, 12:33 AM
Thanks for the reply.

May I know how to do it in Java class instead of in javascript?

Sorry mate I'm pure ExtJS developer so I cannot help U with Java

3 Jan 2011, 1:02 AM
Does anyone able to help me on this? I believe this is a very common problem to all.

Thank you.