在哪里单击以下对象(按钮),以显示要在Selenium(Webdriver)中显示的值? [英] Where to click on this following object(button), for the values to be displayed in Selenium(Webdriver)?

查看:141
本文介绍了在哪里单击以下对象(按钮),以显示要在Selenium(Webdriver)中显示的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

以上是方法,HTML文件中显示新建"按钮...

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

我正在尝试使用Selenium Webdriver自动执行此操作...下面是我单击按钮的最终方法...

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

按钮的布局如下,Em类的宽度为42,Button的宽度为24....还有它们的快照...

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?

推荐答案

moveToElement(ele,x,y)方法将鼠标移到元素左上角的偏移处.

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.

这篇关于在哪里单击以下对象(按钮),以显示要在Selenium(Webdriver)中显示的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆