如何使用selenium python点击打印图标?

问题描述 投票:0回答:1

如果在 chrome 浏览器中打开 pdf,我尝试单击打印图标,但我无法单击打印图标,请参阅下面的屏幕截图任何人都可以提供帮助。

enter image description here

代码:-

import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup



def main(PDF_URL):
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    browser.maximize_window()
    browser.get(PDF_URL)
    browser.implicitly_wait(180)
    print("browser open successfully..")
    time.sleep(5)
    # soup = BeautifulSoup(browser.page_source, 'html.parser')
    # print(soup)
    print_button = browser.find_element(By.ID, 'toolbar').find_element(By.XPATH, "//cr-icon-button//div[@id='icon']/iron-icon")
    print_button.click()

if __name__ == "__main__":
    PDF_URL = "D:/Sandeep/ATP_Project/Web-Scraping/pdf_save/pdf/10.1055-s-2001-17364.pdf"
    main(PDF_URL)
python selenium-webdriver scrapy
1个回答
0
投票

在这种情况下,您不必单击该打印按钮,只需使用 Ctrl+P 即可打印页面。

您可以看到此页面以获得您想要的答案How to send Ctrl+P in selenium

© www.soinside.com 2019 - 2024. All rights reserved.