【问题标题】:Select multiple drop down options based on the data from excel using selenium web driver使用 selenium web 驱动程序根据 excel 中的数据选择多个下拉选项
【发布时间】:2020-08-11 04:15:53
【问题描述】:

有人可以帮助我如何在下拉列表中选择多个选项(复选框)。需要根据 excel 表中的值选择选项。在测试数据表中,将提供带有部分文本的逗号分隔值,并基于此选择选项。

我的代码:

String[] app=apps.split(",");
    for(String apl:app)
    {
        applications.click();
        System.out.println(apl);
        WebElement selecapp=MainConfig.getDriver().findElement(By.xpath("//label[contains(.,"+apl+")]"));
        selecapp.click();
        Thread.sleep(1000);
    }

Drop down image from application

HTML 代码:

                            <ul class="dropdown-menu selectItems" id="thisWidth" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 35px, 0px);">
                                <li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">Test1 -
                                        Test1
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2121 -
                                        Default
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2139 -
                                        acsIVRautomated
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2160 -
                                        ISurvey121
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2176 -
                                        SurveyDemo2
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2177 -
                                        EditedSurvey
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2179 -
                                        TestSurvey234
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2199 -
                                        ForDeletedfgsdh
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2200 -
                                        SurveyReportTest
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2221 -
                                        SurveyDemo25
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2226 -
                                        TestRuleExpression
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2244 -
                                        TestSurvey
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2251 -
                                        dsg
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">A6235 -
                                        A6235
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2253 -
                                        Survey6235
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2254 -
                                        sdgsdg
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2255 -
                                        Testhhh
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2256 -
                                        GGGGGGGGGGGGGGGGGGGGG
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2257 -
                                        dfgdfg
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2258 -
                                        dfgdfhdh
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2259 -
                                        gfhjfgjfg
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2367 -
                                        TestsampleAuto
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2368 -
                                        sampleA1
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2369 -
                                        sampleA12
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2370 -
                                        sampleA13
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2371 -
                                        sampleA15
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2372 -
                                        sampleA16
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2373 -
                                        sampleA17
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2374 -
                                        Nsy5
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2376 -
                                        NSY1
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2381 -
                                        TestsampleAutomationTestsampleAutomationTestsampleAutomationTestsampleAutomationTestsampleAutomation
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2382 -
                                        Te
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2383 -
                                        Te1
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2384 -
                                        Testing123Testing123Testing123Testing123Testing123Testing123Testing123Testing123Testing123Testing123
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2388 -
                                        CyaraHappyPath
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2403 -
                                        SampleTestAutoWithMoreThanLinkText
                                    </label>
                                </li><li id="app" data-toggle="tooltip" title="">
                                    <label class="dropdown-item">
                                        <input type="checkbox" checked.bind="avl.selected" change.delegate="addAllocation()" id="app" onkeydown="return (event.keyCode!=13);" class="au-target" au-target-id="191">2404 -
                                        Survey2sample
                                    </label>
                                </li><!--anchor-->
                            </ul>
                        </div>

任何帮助将不胜感激。

提前致谢

【问题讨论】:

  • 发布您的相关Html?
  • @KunduK 添加了 HTML 代码。请检查一次。

标签: java selenium selenium-webdriver


【解决方案1】:

我建议诱导WebDriverWait并等待ElementToBeClickable()然后点击。

WebDriverWait wait = new WebDriverWait(MainConfig.getDriver(), TimeSpan.FromSeconds(10));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//label[contains(.,"+apl+")]/input"))).Click();

看看这是否有帮助。

【讨论】:

  • 对不起,这不能解决我的问题。实际上我正在尝试从下拉列表中选择多个复选框选项,这些选项不是使用选择标签编写的。如果你看到 UI 图像,我希望你能得到更好的想法。
猜你喜欢
  • 1970-01-01
  • 2014-06-06
  • 1970-01-01
  • 2018-01-18
  • 2016-11-10
  • 2013-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多