Set Window Size Using PhantomJS and Selenium WebDriver in Python



We can set window size using PhantomJS and Selenium webdriver in Python. To work with the PhantomJS, we should create a driver object of the webdriver.PhantomJS class.

Then pass the path of the phantomjs.exe driver file as a parameter to the Class. Next, to set the window size, we shall use the set_window_size method and pass the dimensions as parameters to the method.

To obtain the window size of the browser, we can use the get_window_size method.

Syntax

driver.set_window_size(800,1000)
print(driver.get_window_size())

Example

from selenium import webdriver
#set phantomjs.exe path
driver = webdriver.PhantomJS(executable_path="C:\phantomjs.exe")
driver.maximize_window()
#launch URL
driver.get("https://www.tutorialspoint.com/index.htm")
#set new window size
driver.set_window_size(800, 880)
#obtain window size
print(driver.get_window_size())
driver.quit()

Output

Updated on: 2021-02-01T11:46:54+05:30

314 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements