单击使用硒的展开和折叠按钮

时间:2020-02-17 15:03:49

标签: python html selenium-webdriver web-scraping

我有一个小组,我必须选择“展开”图标,然后进一步展开。示例:单击用户目录,然后单击“本地目录”

enter image description here

我使用类方法单击“用户目录”,效果很好。但无法进一步发展。我使用Class方法,因为xpath,css选择器不起作用,并且没有元素ID。

a=[]
a=driver.find_elements_by_class_name("bi-tree-view-expand-icon")
a[0].click()

看到的唯一区别是图像标题-展开和折叠

用户目录html代码 enter image description here

本地目录html代码

enter image description here

HTML代码

<div class="bi-tree-view-body-content" style="left: 0px; top: 0px; width: 197px; height: 104px;"><table class="bi-tree-view-table" style="width: 197px;" cellspacing="0"><tbody class=" focused"><tr class=" selected lead" style="height: 18px;"><td style="width: 197px; padding-left: 3px;"><nobr><img title="Collapse" class="bi-tree-view-expand-icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree-view-minus.gif"><img class="icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree_folder_closed.gif">User Directories</nobr></td></tr><tr style="height: 18px;"><td style="width: 197px; padding-left: 22px;"><nobr><img title="Expand" class="bi-tree-view-expand-icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree-view-plus.gif"><img class="icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree_folder_closed.gif">Native Directory</nobr></td></tr><tr style="height: 18px;"><td style="width: 197px; padding-left: 22px;"><nobr><img title="Expand" class="bi-tree-view-expand-icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree-view-plus.gif"><img class="icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree_folder_closed.gif">Honeywell</nobr></td></tr><tr style="height: 18px;"><td style="width: 197px; padding-left: 3px;"><nobr><img title="Expand" class="bi-tree-view-expand-icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree-view-plus.gif"><img class="icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree_folder_closed.gif">Application Groups</nobr></td></tr><tr style="height: 18px;"><td style="width: 197px; padding-left: 3px;"><nobr><img title="Expand" class="bi-tree-view-expand-icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree-view-plus.gif"><img class="icon" alt="" src="https://hyperionqa24.cgate.com/workspace/cache/2020-02-16_11-33-04/bpmstatic/thirdparty/bindows/html/themes/Skyros/images/tree_folder_closed.gif">File System</nobr></td></tr><tr class="vertical-filler" style="height: 14px;"><td style="width: 197px;">&nbsp;</td></tr></tbody></table></div>

使用CSS选择器: -用户目录-.selected > td:nth-child(1) > img:nth-child(1) -本机目录-.focused > tr:nth-child(2) > td:nth-child(1) > img:nth-child(1)

0 个答案:

没有答案