我有以下代码:
<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>
对于我的Selenium测试,我需要点击<i class="jstree-icon jstree-ocl">
,屏幕截图中标记为红色。我想在列表中单击此列表,该列表中还包含<a>
元素title= attribute
。这可能吗?
对于后台:我想在给定的jstree中选择不同的文件,并通过将它们的名称设置为全局值来指向这些文件。如果我想选择"/"
,"etc/"
,"testdirectory"
,然后"test_file.txt"
。
答案 0 :(得分:0)
要点击代表为 WebElement
的<i class="jstree-icon jstree-ocl">
,您可以使用以下代码行:
driver.find_element_by_xpath("//li[@role='treeitem']/i[@class='jstree-icon jstree-ocl' and @role='presentation']").click()
但是查看HTML
似乎我们可能需要在click()
标记上调用<a>
方法,如下所示:
driver.find_element_by_xpath("//li[@role='treeitem']//a[@class='jstree-anchor jstree-grid-col-0']").click()