如何从下拉列表中 select 具有 SELECT OPTION 标签的元素?

How to select an element having SELECT OPTION tags from Dropdown?

我正在使用 WEBDRIVERIO 框架。我在 html 语法中有一个下拉菜单。我尝试使用 ID=question-3

扩展它

之后,我通过选项、值、文本尝试了所有使用 SELECT 的选项。但由于它显然不是 SELECT DROPDOWN,所以 none 有效。我尝试根据输入或标签选项单击定位器,但收到 "element not visible" 错误消息。

<div id="question-3" class="question ">
    <div class="single-dropdown">
        <input type="text" name="input-3" class="js-single-selection" placeholder="gender" data-question-id="3" data-index="3" readonly="" style="width: 77px;">
        <div class="single-select-container" style="display: none;">
    <div class="single-select-item" data-image="">
        <label for="option-0-3" data-open="exampleModal1" class="option-0-3-modal">man</label>
        <input type="checkbox" id="option-0-3" data-answer-type="single" data-question-id="3" value="man" data-index="3">
    </div>

    <div class="single-select-item checked" data-image="">
        <label for="option-1-3" data-open="exampleModal1" class="option-1-3-modal">woman</label>
        <input type="checkbox" id="option-1-3" data-answer-type="single" data-question-id="3" value="woman" data-index="3">
    </div>  
</div>
    </div>
.</div>

我建议单击 Select 项(在本例中为输入),然后执行等待(参见文档:http://webdriver.io/api/utility/waitForVisible.html)。然后在等待它在屏幕上可见后单击下拉项。像这样...

browser.click(selectItem);
browser.waitForVisible(dropdownItem);
browser.click(dropdownItem);

因为 html 显示输入标签。我建议:

 1. type the value in that input box (placeholder="gender")
 2. wait for options to appear (Label tag)
 3. click the appeared item.(Appeared label)

此外,如果您的方案失败,请提供失败的堆栈跟踪。