Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
使用Selenium和Python检查表web中项目的背景_Python_Selenium_Html Table - Fatal编程技术网

使用Selenium和Python检查表web中项目的背景

使用Selenium和Python检查表web中项目的背景,python,selenium,html-table,Python,Selenium,Html Table,图1 图2 我有一张如图1所示的桌子。我需要找到一个无效单元格(有效:绿色背景,无效:红色背景)。如果它们都作为图片有效,我必须按返回上一页 我获得了获取当前页面的脚本: current_page =driver.find_element("//span[@class='currentPage']).get_attribute("innerText") 但我不知道如何循环遍历表的每个单元格,以找到哪一个单元格有效或不有效,或者单击或执行其他操作 提前感谢您的帮

图1

图2

我有一张如图1所示的桌子。我需要找到一个无效单元格(有效:绿色背景,无效:红色背景)。如果它们都作为图片有效,我必须按返回上一页 我获得了获取当前页面的脚本:

current_page =driver.find_element("//span[@class='currentPage']).get_attribute("innerText")
但我不知道如何循环遍历表的每个单元格,以找到哪一个单元格有效或不有效,或者单击或执行其他操作


提前感谢您的帮助

您可以使用driver获得具有特定类/css选择器/任何内容的所有元素。按所需内容查找元素。然后,您可以使用一个简单的
for i in elements
循环遍历元素,并获取每个元素的属性。然后,您可以说如果单元格有效或无效会发生什么。

谢谢@Timeler,我通过
valid\u ext\u list=driver获得元素列表。查找元素(“xpath…”)
但是我如何单击该列表中的任何元素?您可以简单地在有效的\u ext\u列表中为我执行“I.click()