Select 元素与具有 "title" 的元素在同一个列表中

Select element in the same list as element with "title"

我有以下代码:

<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

对于我的 Selenium 测试,我需要单击 <i class="jstree-icon jstree-ocl">,它在屏幕截图中标记为红色。我想在列表中单击此按钮,该列表还具有 <a> 元素,该元素具有 title= attribute。这可能吗?

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

要单击表示为 <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()