python - Webdriver 截图

标签 python selenium selenium-webdriver webdriver

用python在windows上使用Selenium Webdriver截图时,截图直接保存到程序的路径下,有没有办法将.png文件保存到特定目录?

最佳答案

使用 driver.save_screenshot('/path/to/file')driver.get_screenshot_as_file('/path/to/file'):

import selenium.webdriver as webdriver
import contextlib

@contextlib.contextmanager
def quitting(thing):
    yield thing
    thing.quit()

with quitting(webdriver.Firefox()) as driver:
    driver.implicitly_wait(10)
    driver.get('http://www.google.com')
    driver.get_screenshot_as_file('/tmp/google.png') 
    # driver.save_screenshot('/tmp/google.png')

关于python - Webdriver 截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8900073/

相关文章:

python - 在下面的代码中解释打印策略

java - 无法通过 selenium WebDriver 上的 "isDisplyed"检查 WebElement 是否存在

javascript - 如何使用 Selenium 和 Javascript 执行器查询 Canvas?

java - 使用 selenium webdriver 找不到下拉列表元素

python - IPython.display : how to change width, 显示图像的高度和分辨率

python - 读取 .xlsx 文件并将其转换为 csv 并连接

python - 如何计算 USB 3.0 立体相机的深度信息?

selenium - 是否可以将 Java-Enum 作为参数从 cucumber 特征文件中传递

python - 在版本 56.0.2924.87 中,Selenium 在 Chrome 中设置窗口大小失败

python - 我的脚本无法单击某个网格