I'm running a Selenium Python script with chromium chromedriver to automate a browser display with multiple windows.
This script worked on a previous setup with an older pi, I'm migrating it to a new pi as the old one was terribly slow and sadly no longer boots.
After installing Selenium and Chromedriver on the new pi the script works except for any window repositioning does not work.
No matter what I've tried; selenium/chrome will not move the window position.
Version information:
Platform: Raspberry Pi 4 Model B
OS: Debian 12 Bookworm (64-bit)
Python: 3.11.2
Selenium: 4.8.3
Chromium-browser: 122.0.6261.89
Chromedriver: 122.0.6261.89
Installed with the following commands:
sudo apt-get update
sudo apt-get install chromium-chromedriver
sudo apt install python3-selenium
sudo apt install python3-pyvirtualdisplay
Issue:
The window opens in the center of the display and does not move from that position.
The chrome flag/argument --window-position has no effect on the visible position.
set_window_position(x,y) has no effect on the visible position.
get_window_position() returns the position set by the script, but the visible position on the display remains unaffected.
Starting the pyvirtualdisplay has no effect.
set_window_size(width,height) changes the size but does not set it to the dimensions entered. Unsure whether that is related to the issue but it is weird.
Error Reproducable script:
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#display = Display(visible=0, size=(1920, 1080))
#display.start()
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("--window-position=250,250")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://google.com")
print(driver.get_window_size())
print(driver.get_window_position())
driver.set_window_size(250,250)
driver.set_window_position(500,1000)
print(driver.get_window_size())
print(driver.get_window_position())
Output:
{'width': 945, 'height': 1060}
{'x': 10, 'y': 10}
{'width': 532, 'height': 500}
{'x': 500, 'y': 1000}