我正在编写一个代码,该代码应该从3个不同的断点[1280 px,768px和320px]中截取屏幕截图。但是代码我已经拍摄了相同屏幕的3个屏幕截图。
from datetime import datetime
from selenium import webdriver
from pyvirtualdisplay import Display
import time
import argparse
from selenium.webdriver.chrome.options import Options
now = datetime.now().strftime('%d-%m-%Y_%H-%M-%S')
class ScreenshotMaker(object):
def __init__(self, url):
self.url = url
self.display = Display()
self.display.start()
self.driver = webdriver.Chrome('/usr/local/bin/chromedriver')
self.driver.set_page_load_timeout(30)
self.driver.get(url)
self.driver.maximize_window()
def make_screenshots(self):
# Make Screenshot for 1280
self.display = Display(visible=0, size=(1280, 800)).start()
self.driver.get_screenshot_as_file('Breakpoint_1280_Screenshot_%s.png' %(now))
print("Taking Screenshot for Breakpoint 1280")
# Make Screenshot for 768
self.display = Display(visible=0, size=(768, 800)).start()
self.driver.get_screenshot_as_file('Breakpoint_768_Screenshot_%s.png' %(now))
print("Taking Screenshot for Breakpoint 768")
# Make Screenshot for 320
self.display = Display(visible=0, size=(320, 800)).start()
self.driver.get_screenshot_as_file('Breakpoint_320_Screenshot_%s.png' %(now))
print("Taking Screenshot for Breakpoint 320")
def main():
# url = ''
sm = ScreenshotMaker('https://example.com')
sm.make_screenshots()
if __name__ == "__main__":
main()
我需要更改代码需要3个不同的屏幕截图吗?
感谢您的帮助:)