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

Open
Nillouise opened this Issue Jan 9, 2017 · 2 comments

Projects

None yet

2 participants

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

from selenium import webdriver
from PIL import Image

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

fox.get('http://www.bilibili.com/video/online.html')

# 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
fox.quit()

im = Image.open('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
im.save('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?
    binary
  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
jesg commented Jan 18, 2017 edited

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

fox.set_window_size(1280, 1024)
@Nillouise

@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