Search code examples
pythongoogle-chromeselenium-webdriverprintingdriver

Python - cannot use Selenium to hit the final print button


I try to write the code for the web automation, which is: open a tab, login, hit button, and print the page. Everything is running perfect except the last step, which my script cannot click the blue "Print" button shown below. Thanks for the help!

enter image description here

from selenium import webdriver
import time
import logging

def chrome_script():

    driver = webdriver.Chrome('C:\\Users\\Eric\\chromedriver')
    driver.get("https://shop.spira.com/Admin/Orders/Default.aspx")
    driver.implicitly_wait(2)

    driver.find_element_by_id("ctl00_MainContent_LoginDialog1_UserName")
    driver.find_element_by_id("ctl00_MainContent_LoginDialog1_Password")

    driver.find_element_by_id("LoginButton")


    driver.find_element_by_name("ctl00$MainContent$BatchButton").click()

    time.sleep(2)

    driver.find_element_by_name("ctl00$MainContent$Print").click()

    driver.forward()

    driver.find_element_by_xpath('.//button[text()="Print"]').click()


    time.sleep(5)

    return

chrome_script()

Solution

  • That's not HTML, that's part of Chrome's UI. You can tell this by trying to right-click on the dialog and you don't get the context menu.

    You could try sending CTRL+SHIFT+P to open the system print dialog and then ALT+P to print.