2013-06-26 40 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和包含的功能,允許選擇由值的選項,可見文本,得到的期權等名單。