我想在下拉菜單中選擇一個選項。我無法使用選擇,因爲我沒有選擇ID。因爲然後我得到預期的選擇獲得按鈕。Selenium-webdriver幫助需要與選擇下拉菜單,而不是選擇選項
我能夠與打開下拉:
[FindsBy(How = How.XPath, Using = "//button[@data-id='Product_Contractor_Person_Contact_Country']")]
private IWebElement CountryDropdownElement { get; set; }
我的代碼看起來如下:
<div class="col-lg-4 form-group">
<label>
Land
</label>
<label class="select select-block">
<select class="selectpicker" data-width="100%" id="Product_Contractor_Person_Contact_Country" name="Product.Contractor.Person.Contact.Country" style="display: none;">
<option selected="selected" value="NL">Nederland</option>
<option value="BE">Belgie</option>
<option value="FR">Frankrijk</option>
<option value="UK">Engeland</option>
<option value="DE">Duitsland</option>
<option value="SE">Zweden</option>
<option value="ES">Spanje</option>
<option value="IT">Italie</option>
<option value="ZA">Zuid Afrika</option>
<option value="PL">Polen</option>
<option value="UA">Oekraïne</option>
<option value="ID">Indonesië</option>
<option value="HU">Hongarije</option>
<option value="PT">Portugal</option>
</select>
<div class="btn-group bootstrap-select" style="width: 100%;">
<button type="button" class="btn dropdown-toggle selectpicker btn-default" data-toggle="dropdown" data-id="Product_Contractor_Person_Contact_Country" title="Nederland"><span class="filter-option pull-left">Nederland</span> <span class="caret"></span></button>
<div class="dropdown-menu open">
<ul class="dropdown-menu inner selectpicker" role="menu">
<li rel="0" class="selected"><a tabindex="0" class="" style=""><span class="text">Nederland</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="1"><a tabindex="0" class="" style=""><span class="text">Belgie</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="2"><a tabindex="0" class="" style=""><span class="text">Frankrijk</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="3"><a tabindex="0" class="" style=""><span class="text">Engeland</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="4"><a tabindex="0" class="" style=""><span class="text">Duitsland</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="5"><a tabindex="0" class="" style=""><span class="text">Zweden</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="6"><a tabindex="0" class="" style=""><span class="text">Spanje</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="7"><a tabindex="0" class="" style=""><span class="text">Italie</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="8"><a tabindex="0" class="" style=""><span class="text">Zuid Afrika</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="9"><a tabindex="0" class="" style=""><span class="text">Polen</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="10"><a tabindex="0" class="" style=""><span class="text">Oekraïne</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="11"><a tabindex="0" class="" style=""><span class="text">Indonesië</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="12"><a tabindex="0" class="" style=""><span class="text">Hongarije</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
<li rel="13"><a tabindex="0" class="" style=""><span class="text">Portugal</span><i class="glyphicon glyphicon-ok icon-ok check-mark"></i></a></li>
</ul>
</div>
</div>
</label>
</div>
在我使用webdriver的硒與C#。
一旦你得到了下拉webelement又名CountryDropdownElement ..,使用和創建一個選擇實例,然後通過索引/值和往常一樣 –
我用selectElement.SelectByText(的SelectedValue) 我收到了選擇該選項以下錯誤:元素不可見:元素當前不可見,可能不會被操縱 – xxx2017
您可以給出select的完整代碼嗎? –