如何使用python在selenium中通过phantomJS设置屏幕大小? JS可以读取大小。
代码在这里:
driver = PhantomJS()
print driver.get_window_size() # output: {u'width': 400, u'height': 300}
driver.set_window_size(1920, 1080)
print driver.get_window_size() # output: {u'width': 1920, u'height': 1280}
# get screen width and height by js, always 1024 * 768
print driver.execute_script('return window.screen.width') # output: 1024
print driver.execute_script('return window.screen.height') # output: 768
以js获取屏幕尺寸,始终为1024 * 768。