我在做的是:
return element(by.xpath('//*/*[@id = "countyIds"]/option[contains(text(),"'+value+'")]')).click();
但我可以看到它“ctrl + click”会导致两个值保持高亮显示。
HTML:
<select name="countyIds" id="countyIds" class="filter" multiple="">
<option value="864">Banskobystrický kraj</option>
<option value="821" selected="selected">Bratislavský kraj</option>
<option value="892" selected="selected">Košický kraj</option>
<option value="844">Nitriansky kraj</option>
<option value="878">Prešovský kraj</option>
<option value="834">Trenčiansky kraj</option>
<option value="826">Trnavský kraj</option>
<option value="852">Žilinský kraj</option>
</select>
您可以在第二个和第三个选项中看到两个selected
值。如何正常“点击”?
答案 0 :(得分:0)
您可以使用Select对象而不是直接单击:
using OpenQA.Selenium.Support.UI;
// select the drop down list
var countries = driver.FindElement(By.Name("countries"));
//create select element object
var selectElement = new SelectElement(countries);
//select by value
selectElement.SelectByValue("844");
// select by text
selectElement.SelectByText("Prešovský kraj");