import math
from selenium import webdriver
from fpdf import FPDF
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
url= sys.argv[1]
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--incognito')
options.add_argument('--start-maximized')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get(url)
width = driver.execute_script("return Math.max( document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth );")
height = driver.execute_script("return Math.max( document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );")
#driver.set_window_size(width, height)
element = driver.find_element(By.TAG_NAME, 'body')
element.screenshot("file.png")
When I tried to run the above script, it gave me an error
(https://i.sstatic.net/jy76ZyQF.png)
What can I do to be able to perform such an operation on Debian 11 server version (without gui). I tested this for different systems that had a gui such as windows 10 or ubuntu 22.04, and there was no problem.
New contributor
Szymon Baranowicz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.