0

我正在使用 selenium2 和 webdriver 来自动化 Kendo UI,但我无法控制下拉列表以从下拉列表中选择模型值。如何使用 webdriver 命令从 Kendo UI DropDownList 中选择一个值?

4

2 回答 2

0

它未编码为 Select 元素的问题:

<div class="FormLabel">Select Model(s):</div>
<div class="FormInput FixMultiSelect">
<div class="k-widget k-multiselect k-header" unselectable="on" style="">
<div class="k-multiselect-wrap k-floatwrap" unselectable="on">
<ul id="ModelList_taglist" class="k-reset" unselectable="on" role="listbox"></ul>
<input class="k-input" style="width: 25px;" accesskey="" role="listbox" aria-expanded="false" tabindex="0" aria-owns="ModelList_taglist ModelList_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false">
<span class="k-icon k-loading k-loading-hidden"></span>
</div>
<select id="ModelList" data-placeholder="Click Here" multiple="multiple" data-role="multiselect" style="display: none;" aria-disabled="false" aria-readonly="false">
<option value="3">ABCGateway_Model</option>
<option value="25">Jack_Gateway_Model</option>
<option value="4">CC Model_1</option>
<option value="26">Sam_Model_1</option>
</select>
<span style="font-family: 'MyriadPro-Regular',Tahoma,Geneva,sans-serif; font-size: 13px; font-stretch: normal; font-style: normal; font-weight: 400; letter-spacing: normal; text-transform: none; line-height: 16px; position: absolute; visibility: hidden;"></span>
</div>
</div>
</div>
于 2013-09-05T14:45:18.160 回答
-2

只需将您的 WebElement 包装到 Select Object 中,如下所示

Select dropdown = new Select(driver.findElement(By.id("identifier")));

完成此操作后,您可以通过 3 种方式选择所需的值。考虑一个这样的 HTML 文件

<html>
<body>
<select id = "designation">
<option value = "MD">MD</option>
<option value = "prog"> Programmer </option>
<option value = "CEO"> CEO </option>
</option>
</select>
<body>
</html>

现在要识别下拉菜单

Select dropdown = new Select(driver.findElement(By.id("designation")));

要选择它的选项说'程序员'你可以做

dropdown.selectByVisibleText("Programmer ");

或者

dropdown.selectByIndex(1);

或者

dropdown.selectByValue("prog");

快乐编码:)

于 2013-09-05T13:05:49.257 回答