这个错误是由于 WebElement 对象没有 save_screenshot 属性引起的。保存屏幕截图是 WebDriver 对象的方法,而不是 WebElement 对象的方法。

要解决这个问题,你需要将保存屏幕截图的代码从 Find_elements.py 文件中的 Find_elements_area 函数中移到调用该函数的地方(即 cases.py 文件的 info_cases 函数中),并将 driver 对象作为参数传递给 Find_elements_area 函数。

具体的更改如下所示:

在 Find_elements.py 文件中的 Find_elements_area 函数中,删除保存屏幕截图的代码:

# driver.save_screenshot('./screenshots/multiple.png')

在 cases.py 文件的 info_cases 函数中,将保存屏幕截图的代码放在调用 Find_elements_area 函数之前,并将 driver 对象作为参数传递给 Find_elements_area 函数:

# 在调用 Find_elements_area 函数之前保存屏幕截图
driver.save_screenshot('./screenshots/multiple.png')

# 调用 Find_elements_area 函数并传递 driver 对象作为参数
data, data_ele = Find_elements_area(div_element, driver)

通过这些更改,你应该能够解决这个问题。

Python Selenium 错误:'WebElement' 对象没有 'save_screenshot' 属性的解决方法

原文地址: https://www.cveoy.top/t/topic/pcBL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录