Phantomjs get wrong location x axis in some website. #14738

Nillouise opened this Issue Jan 9, 2017 · 2 comments


None yet

2 participants

  1. Which version of PhantomJS are you using? Tip: run phantomjs --version.
  2. What steps will reproduce the problem?

from selenium import webdriver
from PIL import Image

fox = webdriver.PhantomJS(executable_path='phantomjs.exe')


# now that we have the preliminary stuff out of the way time to get that image :D
element = fox.find_element_by_class_name('ebox') # find part of the page you want image of
location = element.location
size = element.size
fox.save_screenshot('screenshot.png') # saves screenshot of entire page

im ='screenshot.png') # uses PIL library to open image in memory

left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']

im = im.crop((left, top, right, bottom)) # defines crop points'bilibiliphantomrect.png') # saves new cropped image

  1. Which operating system are you using?
    win7 x64
  2. Did you use binary PhantomJS or did you compile it from source?
  3. Please provide any additional information below.
    This code get the wrong x axis location,so the capture image is left offset in this website.
    If I change phantomjs to Firefox,it can get correct capture image.
jesg commented Jan 18, 2017 edited

@Nillouise have you tried setting the window size in selenium? eg.

fox.set_window_size(1280, 1024)

@jesg No,I didn't do anything except above code.Actually I try to run the code in the virtual machine and real machine.Both of them get wrong location in this website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment