问题
<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> </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...
Can anyone please help me with this? Which coordinates and object should I target?
回答1:
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.
回答2:
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));
来源:https://stackoverflow.com/questions/11027312/where-to-click-on-this-following-objectbutton-for-the-values-to-be-displayed