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, 2020 in Python by Noor
• 200 points
1,591 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, 2020 in Python by Noor
• 200 points

closed Jan 21, 2020 by Kalgi 786 views
0 votes
0 answers
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,510 points
28,127 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
• 58,020 points
11,729 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,150 points
15,849 views
0 votes
2 answers

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,500 points
13,686 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,149 views
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,910 points
7,228 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP