- 1 year ago
How can I open 2 chrome windows in kiosk mode on 2 monitors with WebDriver in Python (Windows)?
To open 2 Chrome windows in kiosk mode on 2 monitors with WebDriver in Python on Windows, you can follow these steps:
Install the Selenium WebDriver for Python using pip.
Download and install the ChromeDriver executable for your version of Chrome.
Create a Python script that uses Selenium WebDriver to open 2 Chrome windows in kiosk mode on 2 monitors. Here is an example script:
pythonfrom selenium import webdriver
# Create a list of the monitor resolutions
resolutions = [(1920, 1080), (1920, 1080)]
# Create a list of the Chrome window positions and sizes
window_sizes = [(0, 0, resolutions[0][0], resolutions[0][1]), (resolutions[0][0], 0, resolutions[1][0], resolutions[1][1])]
# Create a list of the Chrome options for each window
chrome_options = [webdriver.ChromeOptions(), webdriver.ChromeOptions()]
# Set the kiosk mode and window position and size for each Chrome window
for i in range(len(chrome_options)):
chrome_options[i].add_argument('--kiosk')
chrome_options[i].add_argument(f'--window-position={window_sizes[i][0]},{window_sizes[i][1]}')
chrome_options[i].add_argument(f'--window-size={window_sizes[i][2]},{window_sizes[i][3]}')
# Create a list of the Chrome webdrivers for each window
webdrivers = [webdriver.Chrome('path/to/chromedriver.exe', options=chrome_options[0]),
webdriver.Chrome('path/to/chromedriver.exe', options=chrome_options[1])]
# Open a URL in each Chrome window
urls = ['http://www.google.com', 'http://www.bing.com']
for i in range(len(webdrivers)):
webdrivers[i].get(urls[i])
This script creates 2 Chrome windows, each set to kiosk mode, and positions them on separate monitors using the --window-position
argument. The --window-size
argument is used to set the size of each window. The URLs to open in each window are specified in the urls
list.
Replace
'path/to/chromedriver.exe'
with the actual path to the ChromeDriver executable on your system.Run the script and the two Chrome windows should open in kiosk mode on two monitors.
Note: Keep in mind that this example assumes that your system has two monitors with a resolution of 1920x1080 each. You may need to adjust the resolutions
and window_sizes
lists to match the resolution and arrangement of your own monitors.