Partial screenshot in Linux with Python Selenium

+2 votes

Taking a partial screenshot of an element by its id is possible in windows, but it is not working in Linux can anyone please solve my problem.

Where I did a mistake in my code.

element = driver.find_element_by_id("s_curve")
element.save_screenshot("psr.png")

when it runs in windows, it successfully downloaded a screenshot of an element. but in Linux, it throws exceptions as webdriver exception in save_screenshot line

Jan 21 in Python by Noor
• 200 points
214 views
Hi Noor

Are you using the same browser on Windows and Linux?

Also, could you please post the entire code?

Thanks

Hey @Noor, Do you have the PIL Imaging library, Check it. if you don't have it you can install it with pip install Pillow.

Try after installing this!

sorry for late replay i tried with pil but it is not working perfectly. sometimes it crops exactly and sometimes not. cant trust it
No kalgi different browser for windows and linux. it is working remaining things like title and rest of all things it is giving except screenshot

Thanks
Hi! Could you please share your code?

Thanks!
import sys
import time
import traceback
import subprocess
import datetime

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
#from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from pyvirtualdisplay import Display
from bs4 import BeautifulSoup
from PIL import Image
from io import BytesIO

WEB_URL = "some url here"

driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver',chrome_options=options)

driver.get(WEB_URL)

time.sleep(10)
print(driver.title)
driver.title
print(driver.current_url)
driver.current_url
time.sleep(10)
print "Chrome driver Started"
element = driver.find_element_by_id("mtsvc")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
time.sleep(5)
element = driver.find_element_by_id('s_curve') # find part of the page you want image of

element.save_screenshot("new.png")

driver.close()
May be you should check the version compatibility.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

+1 vote
0 answers

taking partial screenshot with python selenium in linux

is it possible to take screenshot of ...READ MORE

Jan 21 in Python by Noor
• 200 points

closed Jan 21 by Kalgi 122 views
0 votes
1 answer

Create an empty list in python with certain size

Try this instead: lst = [None] * 10 The ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,390 points
7,572 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 57,530 points
5,016 views
+3 votes
5 answers

is python compatible with Linux?

Just follow these three commands and you ...READ MORE

answered Sep 12, 2018 in Python by charlie_brown
• 7,760 points
190 views
0 votes
1 answer

Restart python script automatically even when it crashes in Linux

Maybe this would be more robust? 1) save ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 57,530 points
167 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,050 points
1,505 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
2,593 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
2,047 views