2016-09-04 2 views
1

にselectを使用してドロップダウンにオプションを選択することができ:ない私は、オプションを次でコードドロップダウンを持ってwebdriverを

<select class="col-10 customDropdown focusOutVal xh-highlight" id="SourceOfIncome" name="PrimaryIncome.SourceOfIncome" sb="59436885" style="display: none;"><option value="" class="" selected="selected">Select</option> 
<option value="Employed1" class="">Employed1</option> 
<option value="Employed2" class="">Employed2</option> 
<option selected="Employed3" value="Employed3" class="">Employed3</option> 
<option value="Employed4" class="" selected="selected">Employed4</option> 
<option value="Employed5" class="">Employed5</option> 
<option value="Employed6" class="">Employed6</option> 
<option value="Other" class="">Other*</option> 
</select> 

私はすべてのオプションを印刷検索するには、次のコードを書いた:

私は取得していますすべての要素に同じ値があり、visible-textオプションを使用して特定の要素を選択しているときは、ElementnotVisibleExceptionが返されます。

+0

コードを追加できますか? – Grasshopper

答えて

0

コードでは、最初にコード内に「display:none」があってはいけません。あなたが自分でHTMLを作成したり、別の方法で下垂下が表示されている場合は、 - > style = "display:;">

のようにコードを変更することができます。第2に、すべてのオプションを印刷するため

List(WebElement)allSuggestions = driver.findElements(By.id( "SourceOfIncome")); (WebElement提案:allSuggestions)について
{System.out.printlnは(suggestion.getText());}

0

それは、あなたが "ElementnotVisibleException" を述べたように、それは待ち時間の問題があるようです。コードにWebDriverWaitを導入していない場合は、次を試してください。

Select sel = new Select(new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.id("SourceOfIncome")))); 
    List<WebElement> options = sel.getOptions(); 
    Iterator<WebElement> optionItr = options.iterator(); 
    while(optionItr.hasNext()){ 
     System.out.println(optionItr.next().getText()); 
    } 
関連する問題