ローカルPDFをSeleniumで印刷する

windows 10
python 3.12.3
selenium 4.21.0
webdriver-manager 4.0.1
です。

ローカルPDFをSeleniumで印刷したいのですがうまくできません。

Python

1from time import sleep 2from selenium import webdriver 3from selenium.webdriver.chrome.service import Service as ChromeService 4from webdriver_manager.chrome import ChromeDriverManager 5from selenium.webdriver.chrome.options import Options 6from selenium.webdriver.common.keys import Keys 7from selenium.webdriver.common.by import By 8from selenium.webdriver.support.select import Select 9 10options = Options()11# options.add_argument("--headless=new")12options.add_argument("--incognito")13options.add_argument('--ignore-certificate-errors')14options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")15 16driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)17driver.implicitly_wait(10)18 19driver.get(テスト.pdf")20 21driver.quit()

driver.get(テスト.pdf")の後、pyautoguiでゴリゴリやれば印刷できましたが、そうではなくSeleniumで印刷アイコンをクリックしたいのです。

ですが、おそらくshadow-rootとかの関係でうまくいきません。

shadow_content = find_element(By.CSS_SELECTOR, 'cr-icon-button#print').shadow_root

等で指定してもうまくいきません。

どのようにすればクリックできるでしょうか。
宜しくお願いします。

コメントを投稿

0 コメント