デジタルサイネージ … Chrome をキオスクモードで起動する Python Selenium スクリプト

Posted by: ytyng 1 month, 2 weeks ago

Python Selenium でサイトを開いて、Google ログインするスクリプト

#!/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)
# Python スクリプトが終わっても起動しっぱなしにする
options.add_experimental_option('detach', True)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_experimental_option('useAutomationExtension', False)

# 自己署名証明書を受け入れる場合の設定
capabilities = DesiredCapabilities.CHROME
capabilities['acceptInsecureCerts'] = True
# capabilities['acceptSslCerts'] = True # この設定は意味無いかも

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()
Currently unrated

Comments

Archive

2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011