I’m an amateur coder and I’m trying to resize the chrome application by pressing a key on my keyboard by using python. I want my code to be able to resize the window to (300, 1080) and (1920, 300), as well as another key to return to fullscreen. I started researching online and most sources said to use selenium to do this, but using their exact code would just open a new chrome application rather than resize the current one. Other sources told me to use pywinauto, win32gui, or pygetwindow but again all of the code they provided either did nothing or opened a new window.
I tried this but it said module ‘selenium.webdriver’ has no attribute ‘set_window_size’
from selenium import webdriver
webdriver.set_window_size(1920, 1080)
size = webdriver.get_window_size()
print("Window size: width = {}px, height = {}px.".format(size["width"], size["height"]))
I also tried this but it opened a new window rather than resize the current one
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.google.com/chrome/")
driver.set_window_size(800, 880)
Out of desperation I asked chatGPT but it said that its pretty hard to do this but I thought I would at least reach out to some ppl who actually know what their doing before I give up. If anyone could help it would be much appreciated
Penguin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.