1

我在选择下拉菜单时遇到问题,该下拉菜单也是使用 selenium webdriver 和 java 的输入字段。

1)弹出窗口出现后,我将不得不单击下拉菜单并选择一个字段,然后将选项卡转到下一个下拉菜单,然后再选择一个下拉菜单并选择一个字段。2)这些下拉菜单也充当输入字段,因此我将输入 id 用于我的 xpath,它确实在框中输入而不是选择它。现在我不想走那条路线。而是想从下拉列表中进行选择。

这是弹出窗口的 HTML。有任何想法吗??

这是我写的:

 WebElement orgUnitText = driver.findElement(By.xpath("//input[@id='textfield-1137-     inputEl']"));
    orgUnitText.sendKeys("HRD");
    logger.info("entered OrgUnitText");
    WebElement orgUnitAbb = driver.findElement(By.xpath("//input[@id='textfield-1138-  inputEl']"));
    orgUnitAbb.sendKeys("HRD");
    logger.info("entered OrgUnit abbreviation");
    Thread.sleep(15000);


    List<WebElement> options = driver.findElements(By.id("combobox-1140-inputEl"));
    options.get(0).sendKeys("HR_ADMINS");


    List<WebElement> options2 = driver.findElements(By.id("combobox-1141-inputEl"));
    options2.get(0).sendKeys("HR_USERS");

    WebElement textArea = driver.findElement(By.id("textareafield-1143-inputEl"));
    textArea.sendKeys("HRD");

    WebElement saveButton = driver.findElement(By.xpath("//a[@id='button-1146-btnEl']"));
    saveButton.click();
    logger.info("entered OrgUnit description");



</div>
<div id="orgunitpanel-1134-body" class="x-window-body x-window-body-default x-layout-fit x-closable x-window-body-closable x-window-body-default-closable x-window-body-default x-window-body-default-closable" style="background: none repeat scroll 0% 0% white; width: 690px; left: 0px; top: 20px; height: 178px;">
<div id="form-1135" class="x-panel x-fit-item x-window-item x-panel-default" style="padding: 5px; margin: 0px; width: 688px; height: 176px;">
<div id="form-1135-body" class="x-panel-body x-panel-body-default x-panel-body-default x-docked-noborder-top x-docked-noborder-right x-docked-noborder-bottom x-docked-noborder-left" style="width: 678px; left: 0px; top: 0px; height: 166px;">
<span id="form-1135-outerCt" style="display: table; width: 100%; table-layout: fixed;">
</div>
</div>
</div>
<div id="toolbar-1145" class="x-toolbar x-docked x-toolbar-footer x-docked-bottom x-toolbar-docked-bottom x-toolbar-footer-docked-bottom x-box-layout-ct" style="width: 690px; right: auto; left: 4px; top: 202px;">
<div id="toolbar-1145-innerCt" class="x-box-inner " role="presentation" style="width: 684px; height: 22px;">
<div id="toolbar-1145-targetEl" class="x-box-target" style="width: 684px;">
</div>
</div>
</div>
<div id="boundlist-1150" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-resizable x-boundlist-resizable x-boundlist-default-resizable" tabindex="-1" style="right: auto; left: 1101px; top: 407px; width: 176px; z-index: 29001; height: auto; display: none;">
<div id="boundlist-1150-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;">
<div id="boundlist-1150-southeast-handle" class="x-resizable-handle x-resizable-handle-southeast x-boundlist-handle x-boundlist-handle-southeast x-boundlist-handle-southeast-br x-unselectable" unselectable="on"></div>
</div>
<div id="ext-gen1284" class="x-mask" style="z-index: 29001; width: 176px; height: 133px; right: auto; left: 1101px; top: 407px; visibility: hidden;"></div>
<div id="loadmask-1151" class="x-mask-msg x-layer x-mask-msg-default" style="right: auto; left: 1143px; top: 457px; z-index: 29003; display: none;">
<div id="loadmask-1151-msgEl" class=" x-mask-msg-inner">
</div>
</body>
</html>
4

1 回答 1

0

只需使用包装 WebElement 并包含允许按值选择选项、可见文本、获取选项列表等功能的类 Select。

于 2013-06-26T18:54:38.873 回答