Python-无法使用Selenium按下最终打印按钮 [英] Python - cannot use Selenium to hit the final print button

查看:268
本文介绍了Python-无法使用Selenium按下最终打印按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编写用于Web自动化的代码,即:打开一个选项卡,登录,单击按钮,然后打印页面. 除了最后一步,一切都运行良好,我的脚本无法单击下面显示的蓝色打印"按钮. 感谢您的帮助!

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!

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

推荐答案

那不是HTML,而是Chrome用户界面的一部分.您可以通过右键单击对话框来告知这一点,但不会获得上下文菜单.

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.

您可以尝试发送CTRL + SHIFT + P打开系统打印对话框,然后发送ALT + P进行打印.

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

这篇关于Python-无法使用Selenium按下最终打印按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆