用于<input />标签的Selenium自动化脚本作为选择标记(下拉列表),其中包含复选框以进行多项选择?

时间:2018-05-14 10:40:20

标签: selenium webdriver

任何人都可以帮我在这里找到解决方案

enter image description here

<input>标签的Selenium自动化脚本作为选择标记(下拉列表),其中带有复选框,可供多个选择。

所选值是从excel文件中读取的。请在下面找到代码试用版:

    List<WebElement> elements = (List<WebElement>) driver
            .findElements(By.id("ctl00_ContentPlaceHolder1_rcbClinicians_Input"));
    int numberOfElements = elements.size();
    System.out.println("----size----- " + numberOfElements);
    for (int i = 0; i < numberOfElements; i++) {
        System.out.println(i);
        elements = driver.findElements(By.id("ctl00_ContentPlaceHolder1_rcbClinicians_Input"));
        elements.get(i).click();
    }

请帮我找一个解决方案

     <li>Choose Clincians* </li>
                        <li>
                            <div id="ctl00_ContentPlaceHolder1_rcbClinicians" class="RadComboBox RadComboBox_Default" style="width:500px;white-space:normal;">
    <table summary="combobox" style="border-width:0;border-collapse:collapse;width:100%" class="rcbFocused">
        <tbody><tr>
            <td style="width:100%;" class="rcbInputCell rcbInputCellLeft"><input name="ctl00$ContentPlaceHolder1$rcbClinicians" type="text" class="rcbInput" id="ctl00_ContentPlaceHolder1_rcbClinicians_Input" value="" autocomplete="off"></td>
            <td class="rcbArrowCell rcbArrowCellRight"><a id="ctl00_ContentPlaceHolder1_rcbClinicians_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td>
        </tr>
    </tbody></table>
    <input id="ctl00_ContentPlaceHolder1_rcbClinicians_ClientState" name="ctl00_ContentPlaceHolder1_rcbClinicians_ClientState" type="hidden" autocomplete="off" value="{&quot;logEntries&quot;:[],&quot;value&quot;:&quot;&quot;,&quot;text&quot;:&quot;&quot;,&quot;enabled&quot;:true,&quot;checkedIndices&quot;:[],&quot;checkedItemsTextOverflows&quot;:false}">
</div>
                        </li>


                    </ul>
                       <ul>
                        <li>Choose CaseManagers* </li>
                        <li>
                            <div id="ctl00_ContentPlaceHolder1_rcbCaseManagers" class="RadComboBox RadComboBox_Default" style="width:500px;white-space:normal;">
    <table summary="combobox" style="border-width:0;border-collapse:collapse;width:100%" class="">
        <tbody><tr>
            <td style="width:100%;" class="rcbInputCell rcbInputCellLeft"><input name="ctl00$ContentPlaceHolder1$rcbCaseManagers" type="text" class="rcbInput" id="ctl00_ContentPlaceHolder1_rcbCaseManagers_Input" value="" autocomplete="off"></td>
            <td class="rcbArrowCell rcbArrowCellRight"><a id="ctl00_ContentPlaceHolder1_rcbCaseManagers_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td>
        </tr>
    </tbody></table>
    <input id="ctl00_ContentPlaceHolder1_rcbCaseManagers_ClientState" name="ctl00_ContentPlaceHolder1_rcbCaseManagers_ClientState" type="hidden" autocomplete="off" value="{&quot;logEntries&quot;:[],&quot;value&quot;:&quot;&quot;,&quot;text&quot;:&quot;&quot;,&quot;enabled&quot;:true,&quot;checkedIndices&quot;:[],&quot;checkedItemsTextOverflows&quot;:false}">
</div>
                        </li>


                    </ul>

1 个答案:

答案 0 :(得分:0)

我在代码中看不到您正在从Excel中读取值。如果你想逐个选择值,你可以在下面的方法中调用你想要选择的值。如果您想要多个选择,可以使用for循环进行修改。

res <- solr_all(base = myBase, rows = 100, verbose=TRUE,
                sort = "unique_id asc",
                fq="*:*",
                cursorMark="*"
               )