首页 > 解决方案 > 如何从下拉列表中选择具有 SELECT OPTION 标签的元素?

问题描述

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

之后,我使用 SELECT 按选项、值、文本尝试了所有选项。但由于它显然不是 SELECT DROPDOWN,所以没有任何效果。我尝试根据输入或标签选项单击定位器,但收到“元素不可见”错误消息。

<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>

标签: javascriptseleniumselenium-webdriverwebdriver-io

解决方案


由于 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)

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


推荐阅读