如何在selenium webdriver java中自动控制telerik radtreeview复选框?

8nuwlpux  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(126)

我必须在seleniumwebdriverjava中测试radtreeview复选框。您能告诉我如何在SeleniumWebDriverJava中使用radtreeview复选框控件自动执行telerik多选下拉列表吗?radtreeview复选框示例
引用url:https://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/checkboxes/defaultcs.aspx
我可以得到所有的父元素,也可以得到子元素。但在循环时,它给出了错误的结果。我可以为父元素创建一个循环。但是如果我尝试基于父元素循环子元素,我就无法得到结果。
代码:

List<WebElement> dropdownParentElementsCollapsebtns = driver
                .findElements(By.xpath("//*[@id='ctl00_PageContent_rgResourceCate_EmbeddedTree']/ul/li/div/span[2]"));
        List<WebElement> dropdownParentElementsChkbxs = driver
                .findElements(By.xpath("//*[@id='ctl00_PageContent_rgResourceCate_EmbeddedTree']/ul/li/div/span[3]"));
        List<WebElement> dropdownParentElementsNames = driver
                .findElements(By.xpath("//*[@id='ctl00_PageContent_rgResourceCate_EmbeddedTree']/ul/li/div/span[4]"));
        List<WebElement> allChildElements = driver
                .findElements(By.xpath("//*[@id='ctl00_PageContent_rgResourceCate_EmbeddedTree']/ul/li/ul/li"));
        List<WebElement> allChildElementsChkbxs = driver.findElements(
                By.xpath("//*[@id='ctl00_PageContent_rgResourceCate_EmbeddedTree']/ul/li/ul/li/div/span[2]"));
        List<WebElement> allChildElementsNames = driver.findElements(
                By.xpath("//*[@id='ctl00_PageContent_rgResourceCate_EmbeddedTree']/ul/li/ul/li/div/span[3]"));

        if (dropdownParentElements.size() < 0) {
            System.out.println("No Elements available");
        } else {
            System.out.println(" Elements available");
        }
        boolean isCheckSelected = false;

        //For Parent Elements
        for (int i = 0; i < dropdownParentElementsChkbxs.size(); i++) {
            WebElement checkbox = dropdownParentElementsChkbxs.get(i);
            WebElement collapsebtn = dropdownParentElementsCollapsebtns.get(i);
            String name = dropdownParentElementsNames.get(i).getText();
            /*
             * if (checkbox.isSelected()) { System.out.println(name +
             * " is Already Selected"); } else { checkbox.click(); System.out.println(name +
             * " is Selected"); }
             */

            if (!(checkbox.isSelected())) {
                checkbox.click();
                isCheckSelected = true;
            }
            if (isCheckSelected == true) {
                collapsebtn.click();
            }

        }

        //List<String> SelectedChapList = new ArrayList<String>();

        //Looping child based on parent
        for (int i = 0; i < dropdownParentElementsChkbxs.size(); i++) {
            dropdownParentElementsChkbxs.get(i).click();
            WebElement collapsebtn = dropdownParentElementsCollapsebtns.get(i);
            collapsebtn.click();
            for (WebElement childelementChkbx : allChildElementsChkbxs) {
                System.out.println(childelementChkbx.getAttribute("class"));
                if (childelementChkbx.getAttribute("class") == "rtUnchecked") {
                    childelementChkbx.click();
                }

            }
        }

如果有人知道的话,请告诉我@灰胡子@konstantin pribluda@yadav manish
谢谢您

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题