How to set ViewPort size in Python Selenium PhantomJS

Trying to figure out how I can set the size of the viewport (initial window size). I already know what I can use, driver.set_window_size(1920,1080)but it only sets the window size for 1 tab, if more than 1 tab is open, other tabs do not have that size. In addition, I think that it sets the window size only after rendering the page, I want the window size to already be set before the page is rendered. Below is what I have tried so far. If anyone knows how to set the size of the viewport, this will be much appreciated.

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)

dcap["phantomjs.page.settings.userAgent"] = (
    "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 "
    "(KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
)

dcap["phantomjs.page.settings.viewportSize"] = (
    "width: 1920, "
    "height: 1080"
)

driver = webdriver.PhantomJS(desired_capabilities=dcap)

driver.get('https://www.test.com')
+5
source share

Source: https://habr.com/ru/post/1674990/


All Articles