2013-06-26 37 views
1

选择一个项目有一个问题,而选择一个下拉这也是使用硒的webdriver和Java输入字段。如何在下拉使用的webdriver(使用或不使用XPath)

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> 

回答

0

只需使用类选择包装WebElement和包含的功能,允许选择由值的选项,可见文本,得到的期权等名单。