How to set window size using phantomjs and selenium webdriver in Python?

PythonServer Side ProgrammingProgramming

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

raja
Published on 01-Feb-2021 11:42:30
Advertisements