选择与“title”元素位于同一列表中的元素

2024-05-19 07:57:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

<div id="filebrowser" class="jstree jstree-1 jstree-grid-cell jstree-default jstree-checkbox-selection" role="tree" aria-multiselectable="true" tabindex="0" aria-activedescendant="-3" aria-busy="false" aria-selected="false">
    <ul class="jstree-container-ul jstree-children" role="group">
        <li role="treeitem" aria-selected="false" aria-level="1" aria-labelledby="-3_anchor" aria-expanded="false" id="-3" class="jstree-node  jstree-last jstree-closed" aria-busy="false">
            <i class="jstree-icon jstree-ocl" role="presentation"></i>
            <a class="jstree-anchor jstree-grid-col-0" href="#" tabindex="-1" id="-3_anchor" title="/">
                <i class="jstree-icon jstree-checkbox" role="presentation"></i>
                <i class="jstree-icon jstree-themeicon glyphicon glyphicon-folder-close jstree-themeicon-custom" role="presentation"></i>/
            </a>
        </li>
    </ul>
</div>

Screenshot

对于我的硒测试,我需要点击屏幕截图中标记为红色的<i class="jstree-icon jstree-ocl">。我想在列表中单击这个,它也有一个<a>元素,它有一个title= attribute。有可能吗?你知道吗

作为背景:我想在给定的jstree中选择不同的文件,并通过将它们的名称设置为全局值来指向这些文件。如果我想选择"/""etc/""testdirectory"然后"test_file.txt"。你知道吗


Tags: dividfalsejstreepresentationulclassgrid
1条回答
网友
1楼 · 发布于 2024-05-19 07:57:20

要单击表示为<i class="jstree-icon jstree-ocl">WebElement,可以使用以下代码行:

driver.find_element_by_xpath("//li[@role='treeitem']/i[@class='jstree-icon jstree-ocl' and @role='presentation']").click()

但是查看HTML似乎我们必须调用<a>标记上的click()方法,如下所示:

driver.find_element_by_xpath("//li[@role='treeitem']//a[@class='jstree-anchor jstree-grid-col-0']").click()

相关问题 更多 >

    热门问题