【问题标题】:Finding and clicking an check box that is part of the jstree using xpath?使用 xpath 查找并单击属于 jstree 一部分的复选框?
【发布时间】:2016-06-01 20:18:44
【问题描述】:

我正在尝试单击作为 jstree 一部分的复选框,到目前为止我尝试过的每件事都没有成功。请协助。 目标是勾选 id 为 733 的复选框

这是 HTML 代码:

<div id="jstree-1" class="jstree jstree-2 jstree-default jstree-default-responsive jstree-checkbox-no-clicked" role="tree" aria-activedescendant="8528">
<ul class="jstree-container-ul jstree-no-dots jstree-no-icons">
    <li id="733" class="jstree-node jstree-open jstree-last" role="treeitem" aria-selected="false" aria-expanded="true">
        <i class="jstree-icon jstree-ocl"/>
        <a class="jstree-anchor" href="#">
            <i class="jstree-icon jstree-checkbox"/>
            <i class="jstree-icon jstree-themeicon false jstree-themeicon-custom"/>
            Accepts Cash
        </a>
        <ul class="jstree-children" role="group" style="">
    </li>
</ul>

我正在尝试单击复选框,该复选框使用带有 JAVA 的 selenium webdriver 出现在 jstree 中。

这是我迄今为止尝试过但没有成功的事情。

解决方案 1:

driver.findElement(By.xpath(".//li[@id = '733']/a/i[@class = 'jstree-icon jstree-checkbox']")).click();

解决方案 2:

driver.findElement(By.id("733")).sendKeys(Keys.SPACE);

解决方案 3:

WebElement element = driver.findElement(By.xpath(".//*[@id='733']/a/i[1]"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();

解决方案 4:

driver.findElement(By.xpath(".//*[@id='733']/a/i[1]")).click();

所有命令后跟下面一行

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

我不断收到以下错误代码:

unknown error: Element is not clickable at point (695, 507). Other element would receive the click: <a class="jstree-anchor" href="#">...</a>

这是执行所有给定解决方案后发生的情况:

Dropdown box opens up but is not getting clicked

After checkbox is clicked in frontend

以下代码行添加到 HTML:

<span class="selectedCount" data-count="4"> (4)</span>

【问题讨论】:

    标签: javascript java node.js selenium-webdriver jstree


    【解决方案1】:

    我认为问题在于您正在尝试单击&lt;i&gt;,而实际上&lt;a&gt; 是可单击的。试试这个:

    driver.findElement(By.xpath(".//li[@id='733']/a")).click();
    

    【讨论】:

    • 您好,感谢您的回复,我已附上一张图片以显示最终结果,下拉框已打开但复选框从未被选中。
    • 检查元素时HTML如何变化?
    • @maxshaw 我遇到了类似的问题,我需要单击一个选项卡以获取更多选项,然后选择一个选项并单击它。我不得不使用 driver.find_element_by_xpath().click() 两次,两个按钮的 id 一个接一个。
    • 我添加了单击复选框后出现的额外 HTML 行。基里尔,抱歉。
    • @Vivek 也尝试过,但没有成功,下拉框被展开,但复选框从未被选中,请参考附上的两张图片。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 2022-11-05
    • 1970-01-01
    相关资源
    最近更新 更多