driver.get_screenshot_as_file
时间: 2023-10-02 13:11:51 浏览: 112
() is a method in Selenium WebDriver which is used to take a screenshot of the current web page and save it as a file on the local machine.
Syntax:
driver.get_screenshot_as_file(filename)
Parameters:
- filename: The name of the file to which the screenshot will be saved. It should have a .png extension.
Example:
Let's say we want to take a screenshot of the Google homepage and save it as "google.png". Here's how we would do it:
from selenium import webdriver
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
# Navigate to the Google homepage
driver.get("https://www.google.com")
# Take a screenshot and save it as "google.png"
driver.get_screenshot_as_file("google.png")
# Close the browser
driver.quit()
This will save a screenshot of the Google homepage as "google.png" in the current working directory.
阅读全文