Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用selenium单击展开和折叠按钮_Python_Html_Selenium Webdriver_Web Scraping - Fatal编程技术网

Python 使用selenium单击展开和折叠按钮

Python 使用selenium单击展开和折叠按钮,python,html,selenium-webdriver,web-scraping,Python,Html,Selenium Webdriver,Web Scraping,我有一个组,我必须选择展开图标,然后进一步展开。示例:单击用户目录,然后单击“本机目录” 我使用class方法点击“用户目录”,效果很好。但是不能再往前走了。我使用类方法,因为xpath、css选择器不起作用,并且没有元素ID a=[] a=driver.find_elements_by_class_name("bi-tree-view-expand-icon") a[0].click() 唯一不同的是看到的是图像标题-展开和折叠 用户目录html代码 本机目录html代码 <div

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

我使用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;">&nbsp;</td></tr></tbody></table></div>

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:n子目录(1)>img:n子目录(1)

-本机目录-
.focused>tr:nth child(2)>td:nth child(1)>img:nth child(1)

如果
a[0]
是用户目录,那么
a[1]
不是本机目录吗?不,它将跳转到下一个列表。即应用程序组。请查看URL中的图像-可以粘贴完整目录树的html代码吗?也许一个不同构造的
xpath
可能会有所帮助。或者,调试并找出
a
的内容,然后选择正确的a[index]。请阅读原因。粘贴代码并正确设置格式。我们需要更多用于expando切换的周围HTML。如果
a[0]
是用户目录,那么
a[1]
是否不是本机目录?不,它将跳转到下一个列表。即应用程序组。请查看URL中的图像-可以粘贴完整目录树的html代码吗?也许一个不同构造的
xpath
可能会有所帮助。或者,调试并找出
a
的内容,然后选择正确的a[index]。请阅读原因。粘贴代码并正确格式化。我们需要更多的用于expando切换的周围HTML。