python - 使用 selenium 单击展开和折叠按钮
问题描述
我有一个组,我必须选择展开图标,然后进一步展开。示例:单击用户目录,然后单击“本机目录”
我使用类方法单击“用户目录”,效果很好。却无法更进一步。我使用了 Class 方法,因为 xpath,css 选择器不起作用并且没有元素 ID。
a=[]
a=driver.find_elements_by_class_name("bi-tree-view-expand-icon")
a[0].click()
唯一的区别是图片标题 - 展开和折叠
本机目录 html 代码
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;"> </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)
解决方案
推荐阅读
- angular - 构造函数注入影响基本测试问题
- python - 如何在使用 selenium python 隐藏锚标记href属性时获取它
- xcuitest - XCUITest - 如何访问 XCUITest 中的应用设备令牌以触发推送通知,但无需在应用代码中设置任何 UIView?
- ruby-on-rails - has_many :通过一次调用在连接表中添加额外的参数(对象创建)
- python - Matplotlib:脚本等待“输入()”时无法操作绘图
- excel - 进行组合并检查每个可行的组合
- session - Redis Sentinel,Standalone 还是 Cluster,哪个最适合 session?
- sql-server - 连接到不同的服务器并使用批量插入
- javascript - JavaScript/NodeJS:检查 instanceof 的父方法
- c# - 来自字节数组 Cocoa 应用 Xamarin C# 的 NSImage 源