Digital Signage: Python Selenium Script to Launch Chrome in Kiosk Mode
Python
2022-04-02 05:32 (4 years ago)

Script to Open a Website and Login to Google Using Python Selenium
#!/usr/bin/env bash
import os
import time
import dotenv
from selenium.webdriver import Chrome, ChromeOptions, DesiredCapabilities
def create_driver():
options = ChromeOptions()
arguments = [
'--lang=ja',
# '--window-size=1920,1080',
# '--window-position=0,0',
'--kiosk',
'--start-fullscreen',
'--noerrdialogs',
'--disable-translate',
'--disable-infobars',
'--disable-features=TranslateUI',
]
for arg in arguments:
options.add_argument(arg)
# Keep the browser running even after the Python script ends
options.add_experimental_option('detach', True)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_experimental_option('useAutomationExtension', False)
# Settings to accept self-signed certificates
capabilities = DesiredCapabilities.CHROME
capabilities['acceptInsecureCerts'] = True
# capabilities['acceptSslCerts'] = True # This setting might be unnecessary
driver = Chrome(options=options, desired_capabilities=capabilities)
return driver
def main():
dotenv.load_dotenv()
driver = create_driver()
driver.get('https://www.example.com/')
time.sleep(2)
driver.find_element_by_xpath("//*[@id='identifierId']") \
.send_keys(os.environ.get('USER_EMAIL'))
driver.find_element_by_xpath("//*[@id='identifierNext']").click()
time.sleep(2)
driver.find_element_by_xpath(
"//*[@id='password']/div[1]/div/div[1]/input"
).send_keys(os.environ.get('USER_PASSWORD'))
driver.find_element_by_xpath("//*[@id='passwordNext']").click()
if __name__ == '__main__':
main()
Please rate this article (No signup or login required)
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.