Where to click on this following object(button), for the values to be displayed in Selenium(Webdriver)?

江枫思渺然 提交于 2019-12-23 05:08:42

问题


<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...

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!