- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 PyQt5 和 selenium 时,窗口标题显示为“无响应”。脚本执行完成后将显示进度条和控制台发出流。需要帮助来解决这个问题。
from selenium import webdriver
from selenium.common.exceptions import
TimeoutException,NoSuchElementException,ElementClickInterceptedException
from selenium.webdriver.support.ui import WebDriverWait,Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.common.action_chains import ActionChains
import time
import os.path
import pandas as pd
import csv
import threading
from PyQt5 import QtCore, QtGui, QtWidgets
class EmittingStream(QtCore.QObject):
textWritten = QtCore.pyqtSignal(str)
def write(self, text):
self.textWritten.emit(str(text))
class Ui_Fuse(object):
def launch_Selenium_Thread(self):
_translate = QtCore.QCoreApplication.translate
self.pushButton.setEnabled(False)
self.progressBar.setValue(0)
self.textEdit.clear()
t = threading.Thread(target=self.generate())
t.start()
def loaddata(self):
self.completed = 0
while self.completed < 100:
self.completed += 0.0001
self.progressBar.setValue(self.completed)
def setupUi(self, Fuse):
Fuse.setObjectName("Fuse")
Fuse.resize(513, 284)
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
Fuse.setFont(font)
self.label = QtWidgets.QLabel(Fuse)
self.label.setGeometry(QtCore.QRect(90, 67, 71, 20))
self.label.setObjectName("label")
self.LineEdit = QtWidgets.QLineEdit(Fuse)
self.LineEdit.setGeometry(QtCore.QRect(170, 60, 181, 31))
self.LineEdit.setObjectName("textEdit")
self.LineEdit_2 = QtWidgets.QLineEdit(Fuse)
self.LineEdit_2.setGeometry(QtCore.QRect(170, 100, 181, 31))
self.LineEdit_2.setObjectName("textEdit_2")
self.LineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.pushButton = QtWidgets.QPushButton(Fuse)
self.pushButton.setGeometry(QtCore.QRect(169, 150, 90, 31))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.launch_Selenium_Thread)
self.pushButton.clicked.connect(self.loaddata)
self.pushButton_2 = QtWidgets.QPushButton(Fuse)
self.pushButton_2.setGeometry(QtCore.QRect(262, 150, 90, 31))
self.pushButton_2.setObjectName("pushButton_3")
self.pushButton_2.clicked.connect(self.clearall)
self.label_2 = QtWidgets.QLabel(Fuse)
self.label_2.setGeometry(QtCore.QRect(89, 107, 71, 20))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Fuse)
self.label_3.setGeometry(QtCore.QRect(180, 127, 181, 30))
self.label_3.setObjectName("label_3")
self.progressBar = QtWidgets.QProgressBar(Fuse)
self.progressBar.setEnabled(True)
self.progressBar.setGeometry(QtCore.QRect(8, 270, 506, 10))
self.progressBar.setLayoutDirection(QtCore.Qt.LeftToRight)
self.progressBar.setAutoFillBackground(False)
self.progressBar.setProperty("value", 24)
self.progressBar.setAlignment(QtCore.Qt.AlignJustify)
self.progressBar.setInvertedAppearance(False)
self.progressBar.setObjectName("progressBar")
self.textEdit = QtWidgets.QTextEdit(Fuse)
self.textEdit.setGeometry(QtCore.QRect(8, 200, 497, 60))
self.textEdit.setObjectName("textEdit")
self.textEdit.setFont(font)
self.textEdit.setReadOnly(True)
self.retranslateUi(Fuse)
QtCore.QMetaObject.connectSlotsByName(Fuse)
def retranslateUi(self, Fuse):
_translate = QtCore.QCoreApplication.translate
Fuse.setWindowTitle(_translate("Fuse", "Fuse | Invoice Generation"))
self.label.setText(_translate("Fuse", "<html><head/><body><p><span style=\" font-size:10pt; font-weight:600;\">User Name</span></p></body></html>"))
self.pushButton.setText(_translate("Fuse", "Submit"))
self.pushButton_2.setText(_translate("Fuse", "Reset"))
self.label_2.setText(_translate("Fuse", "<html><head/><body><p><span style=\" font-size:10pt; font-weight:600;\">Password</span></p></body></html>"))
self.label_3.setText(_translate("Fuse", "<html><head/><body><p><span style=\" font-size:7pt; color:red; font-weight:600;\">Invalid User Name or Password</span></p></body></html>"))
self.label_3.hide()
Fuse.setWindowFlags( QtCore.Qt.CustomizeWindowHint | QtCore.Qt.MSWindowsFixedSizeDialogHint |QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint )
def clearall(self):
self.LineEdit.clear()
self.LineEdit_2.clear()
self.label_3.clear()
self.textEdit.clear()
self.LineEdit.setEnabled(True)
self.LineEdit_2.setEnabled(True)
self.pushButton.setEnabled(True)
def __init__(self, parent=None, **kwargs):
sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
sys.stderr = EmittingStream(textWritten=self.normalOutputWritten)
def __del__(self):
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
def normalOutputWritten(self, text):
cursor = self.textEdit.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.textEdit.setTextCursor(cursor)
self.textEdit.ensureCursorVisible()
def generate(self):
self.LineEdit.setEnabled(False)
self.LineEdit_2.setEnabled(False)
self.pushButton.setEnabled(False)
self.textEdit.clear()
options = Options()
options.add_argument("--headless")
profile = FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=profile,firefox_options=options,executable_path= os.path.expandvars('%userprofile%\\Desktop\\RPA\\Tools\\geckodriver.exe'))
driver.get("https://example.com/Login.aspx")
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, "loginBtnn")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
search_field = driver.find_element_by_id("txtUserName")
search_field.clear()
username = self.LineEdit.text()
search_field.send_keys(username)
search_field = driver.find_element_by_id("txtPassword")
search_field.clear()
password = self.LineEdit_2.text()
search_field.send_keys(password)
time.sleep(5)
driver.find_element_by_id("BtnLogin").click()
self.textEdit.insertPlainText('Clicked on Login')
time.sleep(5)
try:
element = driver.find_element_by_xpath("//span[contains(@id,'lblFailure')]")
if element.text == "Invalid User Name or Password":
self.textEdit.insertPlainText("Invalid User Name or Password")
self.label_3.show()
self.LineEdit.setEnabled(True)
self.LineEdit_2.setEnabled(True)
self.pushButton.setEnabled(True)
driver.quit()
driver.close()
except NoSuchElementException:
self.textEdit.insertPlainText("Correct User Name or Password")
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/form/div[4]/a/img")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
driver.find_element_by_xpath("/html/body/form/div[4]/a/img").click()
self.textEdit.insertPlainText('Clicked Product Links')
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, "lnkFuse")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
driver.find_element_by_id("lnkFuse").click()
self.textEdit.insertPlainText('Clicked on Fuse Link')
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.XPATH, "//span[@class='Invoice Processing'][contains(.,'Invoice Processing')]")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
element_to_hover_over = driver.find_element_by_xpath("//span[@class='Invoice Processing'][contains(.,'Invoice Processing')]")
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
self.textEdit.insertPlainText('Clicked on Invoice Processing')
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.XPATH, "//a[@href='../../RS/Batch/AuditInvoice.aspx']")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
driver.find_element_by_xpath("//a[@href='../../RS/Batch/AuditInvoice.aspx']").click()
self.textEdit.insertPlainText('Clicked on Audit Invoices')
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, "MainContent_ddlSearchInvoiceStatus")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
invoice_audit = 'Audited'
InvoiceStatus = Select(driver.find_element_by_id("MainContent_ddlSearchInvoiceStatus"))
for option in InvoiceStatus.options:
option_text = option.text
if invoice_audit in option_text:
option.click()
break
self.textEdit.insertPlainText('Selected Audited from Dropdown')
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, "MainContent_btnSearch")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
driver.find_element_by_id('MainContent_btnSearch').click()
self.textEdit.insertPlainText('Clicked on Search Button')
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, "MainContent_ddlItemsPerPage")));
except TimeoutException:
self.textEdit.insertPlainText('Timed out waiting for page to load')
element = driver.find_element_by_id('MainContent_ddlItemsPerPage')
element.location_once_scrolled_into_view
driver.find_element_by_id('MainContent_ddlItemsPerPage').click()
items_perpage = '500'
records_list = Select(driver.find_element_by_id("MainContent_ddlItemsPerPage"))
for option in records_list.options:
option_text = option.text
if items_perpage in option_text:
option.click()
break
time.sleep(5)
self.textEdit.insertPlainText('Selected Max items per page')
list_links = driver.find_elements_by_partial_link_text('Generate')
time.sleep(5)
id_list = []
for i in list_links:
data = i.get_attribute('id')
self.textEdit.insertPlainText(data)
id_list.append(data)
id_df = pd.DataFrame(id_list)
self.textEdit.insertPlainText(id_df)
for row in id_df.values:
row_val = str(row)[2:-2]
try:
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, "MainContent_gvAuditInvoice")));
self.textEdit.insertPlainText('Element Found')
element = driver.find_element_by_id(row_val)
element.location_once_scrolled_into_view
WebDriverWait(driver, 60000).until(
EC.element_to_be_clickable((By.ID, row_val)));
driver.find_element_by_id(row_val).click()
localtime = time.strftime("%m-%d-%Y %I:%M:%S")
self.textEdit.insertPlainText(row_val + "|" + 'Clicked' + '|' + localtime)
time.sleep(5)
except ElementClickInterceptedException:
continue
self.textEdit.insertPlainText('Timed out waiting for page to load')
time.sleep(5)
self.textEdit.insertPlainText('Completed')
self.LineEdit.clear()
self.LineEdit_2.clear()
self.label_3.clear()
self.LineEdit.setEnabled(True)
self.LineEdit_2.setEnabled(True)
self.pushButton.setEnabled(True)
self.stop_Selenium_Thread()
def stop_Selenium_Thread(self):
_translate = QtCore.QCoreApplication.translate
self.pushButton.setEnabled(True)
t = threading.Thread(target=self.stop_Selenium_Thread)
for i, t in enumerate(self.generate()):
t.join()
print('Thread {} Stopped'.format(i))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Fuse = QtWidgets.QDialog()
ui = Ui_Fuse()
ui.setupUi(Fuse)
Fuse.show()
sys.exit(app.exec_())
我的实际结果应该是当我点击应用程序上的提交按钮时,程序应该开始执行脚本,并且代码中给出的 self.textEdit.insertPlainText 应该在文本编辑中流动,进度条移动。
最佳答案
首先,您有以下不良编程习惯:
另一方面,转到 Qt 时,您会遇到以下错误:
另一方面,我没有测试您的代码,但我发现您的错误之一是
t = threading.Thread(target=self.generate())
由于您是调用函数而不是将其传递给函数,因此它必须是
t = threading.Thread(target=self.generate)
考虑到上述情况,我实现了以下内容:
fuse_ui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'fuse.ui'
#
# Created by: PyQt5 UI code generator 5.12.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Fuse(object):
def setupUi(self, Fuse):
Fuse.setObjectName("Fuse")
Fuse.resize(556, 513)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Fuse.sizePolicy().hasHeightForWidth())
Fuse.setSizePolicy(sizePolicy)
self.verticalLayout = QtWidgets.QVBoxLayout(Fuse)
self.verticalLayout.setObjectName("verticalLayout")
spacerItem = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.verticalLayout.addItem(spacerItem)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
spacerItem1 = QtWidgets.QSpacerItem(80, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem1)
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.userNameLabel = QtWidgets.QLabel(Fuse)
self.userNameLabel.setObjectName("userNameLabel")
self.gridLayout.addWidget(self.userNameLabel, 0, 0, 1, 1)
self.userNameLineEdit = QtWidgets.QLineEdit(Fuse)
self.userNameLineEdit.setObjectName("userNameLineEdit")
self.gridLayout.addWidget(self.userNameLineEdit, 0, 1, 1, 1)
self.passwordLabel = QtWidgets.QLabel(Fuse)
self.passwordLabel.setObjectName("passwordLabel")
self.gridLayout.addWidget(self.passwordLabel, 1, 0, 1, 1)
self.passwordLineEdit = QtWidgets.QLineEdit(Fuse)
self.passwordLineEdit.setObjectName("passwordLineEdit")
self.gridLayout.addWidget(self.passwordLineEdit, 1, 1, 1, 1)
self.invalidLabel = QtWidgets.QLabel(Fuse)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.invalidLabel.sizePolicy().hasHeightForWidth())
self.invalidLabel.setSizePolicy(sizePolicy)
self.invalidLabel.setAlignment(QtCore.Qt.AlignCenter)
self.invalidLabel.setObjectName("invalidLabel")
self.gridLayout.addWidget(self.invalidLabel, 2, 1, 1, 1)
self.widget = QtWidgets.QWidget(Fuse)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
self.widget.setSizePolicy(sizePolicy)
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.submitButton = QtWidgets.QPushButton(self.widget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.submitButton.sizePolicy().hasHeightForWidth())
self.submitButton.setSizePolicy(sizePolicy)
self.submitButton.setObjectName("submitButton")
self.horizontalLayout.addWidget(self.submitButton)
self.resetButton = QtWidgets.QPushButton(self.widget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.resetButton.sizePolicy().hasHeightForWidth())
self.resetButton.setSizePolicy(sizePolicy)
self.resetButton.setObjectName("resetButton")
self.horizontalLayout.addWidget(self.resetButton)
self.gridLayout.addWidget(self.widget, 3, 1, 1, 1)
self.horizontalLayout_2.addLayout(self.gridLayout)
spacerItem2 = QtWidgets.QSpacerItem(80, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
spacerItem3 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.verticalLayout.addItem(spacerItem3)
self.logTextEdit = QtWidgets.QTextEdit(Fuse)
self.logTextEdit.setObjectName("logTextEdit")
self.verticalLayout.addWidget(self.logTextEdit)
self.progressBar = QtWidgets.QProgressBar(Fuse)
self.progressBar.setProperty("value", 24)
self.progressBar.setObjectName("progressBar")
self.verticalLayout.addWidget(self.progressBar)
self.retranslateUi(Fuse)
QtCore.QMetaObject.connectSlotsByName(Fuse)
def retranslateUi(self, Fuse):
_translate = QtCore.QCoreApplication.translate
Fuse.setWindowTitle(_translate("Fuse", "Dialog"))
self.userNameLabel.setText(_translate("Fuse", "<html><head/><body><p><span style=\" font-weight:600;\">User Name</span></p></body></html>"))
self.passwordLabel.setText(_translate("Fuse", "<html><head/><body><p><span style=\" font-weight:600;\">Password</span></p></body></html>"))
self.invalidLabel.setText(_translate("Fuse", "<html><head/><body><p><span style=\" font-size:7pt; color:red; font-weight:600;\">Invalid User Name or Password</span></p></body></html>"))
self.submitButton.setText(_translate("Fuse", "Submit"))
self.resetButton.setText(_translate("Fuse", "Reset"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Fuse = QtWidgets.QDialog()
ui = Ui_Fuse()
ui.setupUi(Fuse)
Fuse.show()
sys.exit(app.exec_())
fusi_worker.py
import os
import time
from selenium import webdriver
from selenium.common.exceptions import TimeoutException,NoSuchElementException,ElementClickInterceptedException
from selenium.webdriver.support.ui import WebDriverWait,Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.common.action_chains import ActionChains
from PyQt5 import QtCore
import pandas as pd
class FusiWorker(QtCore.QObject):
progressChanged = QtCore.pyqtSignal(int)
logSignal = QtCore.pyqtSignal(str)
invalidSignal = QtCore.pyqtSignal()
finished = QtCore.pyqtSignal()
@QtCore.pyqtSlot(str, str)
def start(self, username, password):
options = Options()
options.add_argument("--headless")
profile = FirefoxProfile()
driver_path = os.path.expandvars('%userprofile%\\Desktop\\RPA\\Tools\\geckodriver.exe')
driver = webdriver.Firefox(firefox_profile=profile, options=options, executable_path=driver_path)
driver.get("https://example.com/Login.aspx")
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, "loginBtnn")));
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
search_field = driver.find_element_by_id("txtUserName")
search_field.clear()
search_field.send_keys(password)
time.sleep(5)
driver.find_element_by_id("BtnLogin").click()
self.logSignal.emit('Clicked on Login')
time.sleep(5)
try:
element = driver.find_element_by_xpath("//span[contains(@id,'lblFailure')]")
if element.text == "Invalid User Name or Password":
self.logSignal.emit("Invalid User Name or Password")
self.invalidSignal.emit()
driver.quit()
driver.close()
except NoSuchElementException:
self.logSignal.emit("Correct User Name or Password")
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.XPATH, "/html/body/form/div[4]/a/img")));
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
driver.find_element_by_xpath("/html/body/form/div[4]/a/img").click()
self.logSignal('Clicked Product Links')
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, "lnkFuse")));
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
driver.find_element_by_id("lnkFuse").click()
self.logSignal.emit('Clicked on Fuse Link')
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='Invoice Processing'][contains(.,'Invoice Processing')]")));
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
element_to_hover_over = driver.find_element_by_xpath("//span[@class='Invoice Processing'][contains(.,'Invoice Processing')]")
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
self.logSignal.emit('Clicked on Invoice Processing')
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.XPATH, "//a[@href='../../RS/Batch/AuditInvoice.aspx']")))
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
driver.find_element_by_xpath("//a[@href='../../RS/Batch/AuditInvoice.aspx']").click()
self.logSignal.emit('Clicked on Audit Invoices')
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, "MainContent_ddlSearchInvoiceStatus")))
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
invoice_audit = 'Audited'
InvoiceStatus = Select(driver.find_element_by_id("MainContent_ddlSearchInvoiceStatus"))
for option in InvoiceStatus.options:
option_text = option.text
if invoice_audit in option_text:
option.click()
break
self.logSignal.emit('Selected Audited from Dropdown')
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, "MainContent_btnSearch")))
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
driver.find_element_by_id('MainContent_btnSearch').click()
self.logSignal.emit('Clicked on Search Button')
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, "MainContent_ddlItemsPerPage")))
except TimeoutException:
self.logSignal.emit('Timed out waiting for page to load')
element = driver.find_element_by_id('MainContent_ddlItemsPerPage')
element.location_once_scrolled_into_view
driver.find_element_by_id('MainContent_ddlItemsPerPage').click()
items_perpage = '500'
records_list = Select(driver.find_element_by_id("MainContent_ddlItemsPerPage"))
for option in records_list.options:
option_text = option.text
if items_perpage in option_text:
option.click()
break
time.sleep(5)
self.logSignal.emit('Selected Max items per page')
list_links = driver.find_elements_by_partial_link_text('Generate')
time.sleep(5)
id_list = []
for i in list_links:
data = i.get_attribute('id')
self.logSignal.emit(data)
id_list.append(data)
# TODO
id_df = pd.DataFrame(id_list)
self.logSignal.emit(id_df.to_string())
for row in id_df.values:
row_val = str(row)[2:-2]
try:
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, "MainContent_gvAuditInvoice")))
self.logSignal.emit('Element Found')
element = driver.find_element_by_id(row_val)
element.location_once_scrolled_into_view
WebDriverWait(driver, 60000).until(EC.element_to_be_clickable((By.ID, row_val)))
driver.find_element_by_id(row_val).click()
localtime = time.strftime("%m-%d-%Y %I:%M:%S")
self.logSignal.emit(row_val + "|" + 'Clicked' + '|' + localtime)
time.sleep(5)
except ElementClickInterceptedException:
continue
self.logSignal.emit('Timed out waiting for page to load')
time.sleep(5)
self.logSignal.emit('Completed')
self.finished.emit()
@QtCore.pyqtSlot()
def load_data(self):
completed = 0
while completed < 100:
completed += 0.0001
self.progressChanged.emit(completed)
time.sleep(0.01)
main.py
import threading
from PyQt5 import QtCore, QtGui, QtWidgets
from fuse_worker import FusiWorker
from fuse_ui import Ui_Fuse
class Fuse(QtWidgets.QDialog, Ui_Fuse):
def __init__(self, parent=None):
super(Fuse, self).__init__(parent)
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint |
QtCore.Qt.MSWindowsFixedSizeDialogHint |
QtCore.Qt.WindowCloseButtonHint |
QtCore.Qt.WindowMinimizeButtonHint)
self.init()
self.connections()
def init(self):
self._worker = FusiWorker()
self.reset()
thread = QtCore.QThread(self)
thread.start()
self._worker.moveToThread(thread)
self.progressBar.setValue(0)
def connections(self):
self.submitButton.clicked.connect(self.submit)
self.resetButton.clicked.connect(self.reset)
self._worker.logSignal.connect(self.logTextEdit.insertPlainText)
self._worker.invalidSignal.connect(self.invalidate)
self._worker.finished.connect(self.reset)
self._worker.progressChanged.connect(self.progressBar.setValue)
self.progressBar.setValue(0)
@QtCore.pyqtSlot()
def submit(self):
username = self.userNameLineEdit.text()
password = self.passwordLineEdit.text()
self.logTextEdit.clear()
self.userNameLineEdit.setEnabled(False)
self.passwordLineEdit.setEnabled(False)
threading.Thread(target=self._worker.start, args=(username, password,), daemon=True).start()
threading.Thread(target=self._worker.load_data, daemon=True).start()
@QtCore.pyqtSlot()
def reset(self):
self.userNameLineEdit.clear()
self.passwordLineEdit.clear()
self.invalidLabel.hide()
self.userNameLineEdit.setEnabled(True)
self.passwordLineEdit.setEnabled(True)
self.submitButton.setEnabled(True)
@QtCore.pyqtSlot()
def invalidate(self):
self.invalidLabel.show()
self.reset()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Fuse()
w.show()
sys.exit(app.exec_())
这些文件必须位于同一文件夹中:
├── fuse_ui.py
├── fuse_worker.py
└── main.py
关于python - Selenium 的应用程序没有响应 - 不显示进度条,并且在任务完成之前不在控制台中发出文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55308411/
我是 C 语言新手,我编写了这个 C 程序,让用户输入一年中的某一天,作为返回,程序将输出月份以及该月的哪一天。该程序运行良好,但我现在想简化该程序。我知道我需要一个循环,但我不知道如何去做。这是程序
我一直在努力找出我的代码有什么问题。这个想法是创建一个小的画图程序,并有红色、绿色、蓝色和清除按钮。我有我能想到的一切让它工作,但无法弄清楚代码有什么问题。程序打开,然后立即关闭。 import ja
我想安装screen,但是接下来我应该做什么? $ brew search screen imgur-screenshot screen
我有一个在服务器端工作的 UDP 套接字应用程序。为了测试服务器端,我编写了一个简单的 python 客户端程序,它发送消息“hello world how are you”。服务器随后应接收消息,将
我有一个 shell 脚本,它运行一个 Python 程序来预处理一些数据,然后运行一个 R 程序来执行一些长时间运行的任务。我正在学习使用 Docker 并且我一直在运行 FROM r-base:l
在 Linux 中。我有一个 c 程序,它读取一个 2048 字节的文本文件作为输入。我想从 Python 脚本启动 c 程序。我希望 Python 脚本将文本字符串作为参数传递给 c 程序,而不是将
对于一个类,我被要求编写一个 VHDL 程序,该程序接受两个整数输入 A 和 B,并用 A+B 替换 A,用 A-B 替换 B。我编写了以下程序和测试平台。它完成了实现和行为语法检查,但它不会模拟。尽
module Algorithm where import System.Random import Data.Maybe import Data.List type Atom = String ty
我想找到两个以上数字的最小公倍数 求给定N个数的最小公倍数的C++程序 最佳答案 int lcm(int a, int b) { return (a/gcd(a,b))*b; } 对于gcd,请查看
这个程序有错误。谁能解决这个问题? Error is :TempRecord already defines a member called 'this' with the same paramete
当我运行下面的程序时,我在 str1 和 str2 中得到了垃圾值。所以 #include #include #include using namespace std; int main() {
这是我的作业: 一对刚出生的兔子(一公一母)被放在田里。兔子在一个月大时可以交配,因此在第二个月的月底,每对兔子都会生出两对新兔子,然后死去。 注:在第0个月,有0对兔子。第 1 个月,有 1 对兔子
我编写了一个程序,通过对字母使用 switch 命令将十进制字符串转换为十六进制,但是如果我使用 char,该程序无法正常工作!没有 switch 我无法处理 9 以上的数字。我希望你能理解我,因为我
我是 C++ 新手(虽然我有一些 C 语言经验)和 MySQL,我正在尝试制作一个从 MySQL 读取数据库的程序,我一直在关注这个 tutorial但当我尝试“构建”解决方案时出现错误。 (我正在使
仍然是一个初学者,只是尝试使用 swift 中的一些基本函数。 有人能告诉我这段代码有什么问题吗? import UIKit var guessInt: Int var randomNum = arc
我正在用 C++11 编写一个函数,它采用 constant1 + constant2 形式的表达式并将它们折叠起来。 constant1 和 constant2 存储在 std::string 中,
我用 C++ 编写了这段代码,使用运算符重载对 2 个矩阵进行加法和乘法运算。当我执行代码时,它会在第 57 行和第 59 行产生错误,非法结构操作(两行都出现相同的错误)。请解释我的错误。提前致谢:
我是 C++ 的初学者,我想编写一个简单的程序来交换字符串中的两个字符。 例如;我们输入这个字符串:“EXAMPLE”,我们给它交换这两个字符:“E”和“A”,输出应该类似于“AXEMPLA”。 我在
我需要以下代码的帮助: 声明 3 个 double 类型变量,每个代表三角形的三个边中的一个。 提示用户为第一面输入一个值,然后 将用户的输入设置为您创建的代表三角形第一条边的变量。 将最后 2 个步
我是新来的,如果问题不好请见谅 任务:将给定矩阵旋转180度 输入: 1 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 输出: 16 15 14 13 12 11
我是一名优秀的程序员,十分优秀!