I have an error when i try to take a screenshot of a large image with Selenium and Python, with Chrome Driver.I tried a lot of thing since yesterday, but i have still the same error. I have the code to take a screenshot, but with a particular page (1050×8100),
i got the error selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 299,800
The versions are ok ( i dont have any errors on other webpages)
Here are the options I’ve added (after reading several issues on stackoverflow) :
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-setuid-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--hide-scrollbars')
chrome_options.add_argument("--force-device-scale-factor=1")
And here is my code to take the screenshot :
self.driver.get(self.url)
page_width = self.driver.execute_script("return document.body.scrollWidth")
page_height = self.driver.execute_script("return document.body.scrollHeight") self.driver.set_window_size(page_width, page_height)
time.sleep(10)
png = self.driver.get_screenshot_as_png()
image = Image.open(io.BytesIO(png))
screen_path = os.path.join(folder_output_path, str(number_of_screen) + '.png') image.save(screen_path)
When I set the window size with smaller dimensions, it’s running, but I lost information from my page. For a page with:
page_width=1560
and
page_height=7351
it’s running, but for page with (1560×8897) it’s not working.
Someone can help me to get the screenshot of the whole large page?
0
Try to reduce the image quality by adding the optimize
and quality
parameters, this should speed up saving the screenshot, e.g.:
image.save(screen_path, optimize=True, quality=80)
.
You can also try increasing the timeouts needed to load the page, e.g.
self.driver.set_page_load_timeout(120)
.