0
<table id="ext-comp-1389" class="x-btn x-btn-text-icon " cellspacing="0" style="width: auto;">
<tbody class="x-btn-small x-btn-icon-small-left">
<tr>
<tr>
<td class="x-btn-ml">
<td class="x-btn-mc">
<em class="x-btn-split" unselectable="on">
<button id="ext-gen128" class="x-btn-text create" type="button">New</button>
</em>
</td>
<td class="x-btn-mr">
<i>&nbsp;</i>
</td>
</tr>
<tr>
</tbody>
</table>

Above is the way, the New button is present in the HTML file...

The behavior of the button is it has a '+' sign present next to it...Only when it is clicked on the '+' sign, does the list of options display....When it is clicked on anywhere else on the button nothing happens...

I am trying to automate this, using Selenium Webdriver...And below is the conclusive way in which I am clicking on the button...

private static int buttonwidth=24;//value got from firebug computation tab...
private static final int Xoffset = (buttonwidth/2)+6;
private static final int Yoffset = 0;
private static int buttonwidth1=42;   
private static final int Xoffset1 = (buttonwidth/2)-6;
private static final int Yoffset1 = 0;
.......    
......
.......


WebElement ele = driver.findElement(By.xpath("//*[@id='ext-gen128']"));//new button's id
Actions build = new Actions(driver);
build.moveToElement(ele, Xoffset, Yoffset).click().build().perform();
WebElement ele1 = driver.findElement(By.xpath("//*[@id='ext-comp-1389']/tbody/tr[2]/td[2]/em"));
Actions build1 = new Actions(driver);
build1.moveToElement(ele, Xoffset1, Yoffset1).click().build().perform();

The layout of the buttons are as follows, Width 42 for Em class and 24 for the Button....Snapshots of them as well...

Em_Class Layout

NewButton_Layout

New Button Image

Can anyone please help me with this? Which coordinates and object should I target?

Manikandan
  • 417
  • 4
  • 8
  • 18

2 Answers2

2

The moveToElement(ele,x,y) method moves the mouse to an offset from the top-left corner of the element.

So I guess you will have to do some calculations to make sure you get the correct coordinates to click on the + symbol.

Hari Reddy
  • 3,808
  • 4
  • 33
  • 42
  • Ok, I was working with from the center of the element!will try and let you know... – Manikandan Jun 14 '12 at 07:40
  • I have a doubt, there are two classes Em, which has the '+' and the button/link, which has the name, 'New' in it..I want to click on the '+'...If I give, click on the Em element, I am getting a message element cannot be located...I had checked the complete xpath, it is proper...is it because, it has the attribute, unclickable='on' that the element is not able to be clicked...Then, I tried by clicking on the button/link, and giving the coordinates outside the button range...will it click on the '+' sign or it will click somewhere outside...?? – Manikandan Jun 14 '12 at 09:00
  • 1
    If there are 2 Em Classes. Which one of those do you want to click on. If there is an attribute called unClickable='on'. You will not be able to click on it. – Hari Reddy Jun 14 '12 at 09:45
  • this question might look funny...but, i don't know the current behavior..hence...**The question"if i click on an element, but give coordinates outside the element range..will the next element be clicked?** Take for ex: the code present in the sample given, ...Inside the button tag, 'New' text is present...Inside the em tag, but outside the button tag, the '+' symbol is present, where we need to click...So, how will you advice, if the em tag has unclickableOn – Manikandan Jun 14 '12 at 10:44
1

Best solution for this kind of problem is, go with Sahi..found it easy to use and has a good functionality .. use the command _click(_xy(_cell("New"),-5,5));

Manikandan
  • 417
  • 4
  • 8
  • 18