0

我正在使用 Selenium 2.0 在我的应用程序上测试 GUI。

当我在输入字段中输入数据时会出现建议框,我需要单击建议框来验证输入。

图片在这里:图片

我的html代码(输入):

<table class="supplier" cellspacing="1" width="100%">
<tbody>
<tr>
<td><span id="supplier:supplierOps" class="ui-autocomplete">
<input id="supplier:supplierOps_input" name="supplier:supplierOps_input" type="text" class="ui-autocomplete-input ui-inputfield ui-widget ui-state-default ui-corner-all" autocomplete="off" value="" size="10" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false">
</span></td>
<td>...</td>
</tr>
</tbody>
</table>

我的 html 代码(建议框):

<table class="ui-autocomplete-items ui-autocomplete-table ui-widget-content ui-widget ui-corner-all ui-helper-reset">
<tbody>
<tr class="ui-autocomplete-item ui-autocomplete-row ui-corner-all ui-state-highlight" data-item-value="1" data-item-label="OPS1">
<td>OPS1 - Supplier1</td>
</tr>
</tbody>
</table>

我的硒代码:

// supplier ops, i find and type data into the input
WebElement eSupplier = driver.findElement(By.id("supplier:supplierOps_input"));
eSupplier.sendKeys("OPS1");
sleep(5); // wait the suggestbox

// i find the suggestbox
WebElement eSupplierSuggest = driver.findElement(By.xpath("//div[@id='supplier:supplierOps_panel']/table/tbody/tr"));
eSupplierSuggest.click();
sleep(5); // wait the refresh for the next field supplierAddress

我的 xpath 和一切似乎都很好。

所以,问题是:我需要捕获/选择什么元素(td,tr,table,...)以及我需要使用什么方法(driver.click(),sendKeys(),...)来验证建议框?

编辑 :

建议框在验证时没有焦点。所以我正在寻找将焦点放在它上面并尝试使用 sendKeys(Keys_ENTER)。将焦点放在 WebElement 上?

编辑2:

一些新闻人员,我将尝试用 Arquillian Graphene 解决它。它是一个强制测试人员编写支持 Ajax 且可重用的测试和测试抽象的框架,

友情链接 : 石墨烯简介 - Graphene 2.0.0.Alpha3 发布 - JBoss Community Graphene2 - Jquery Selector

4

2 回答 2

0

尝试使用 cssSelector 进行自动建议单击,如下所示,如果您仍然遇到问题,请告诉我。

 // supplier ops, i find and type data into the input
    WebElement eSupplier = driver.findElement(By.id("supplier:supplierOps_input"));
    eSupplier.sendKeys("OPS1");
    sleep(5); // wait the suggestbox

    // i find the suggestbox
    WebElement eSupplierSuggest = driver.findElement(By.cssSelector("css path of that specific value in the auto suggestion box"));
    eSupplierSuggest.click();
    sleep(5); // wait the refresh for the next field supplierAddress
于 2013-04-03T10:05:05.047 回答
0

无需单击建议框,您可以找到建议框,然后提取建议框的文本。断言它包含您输入的文本。

于 2013-04-17T03:24:09.113 回答