我想在发生异常时使用python/selenium截图并通过电子邮件发送它?我该怎么做?我不想保存它,但我不介意将其保存到文件夹中,但我想发送一封电子邮件,说明错误发生的位置。到目前为止,我看到的所有示例似乎都是将其保存到文件夹中。下面是我的代码
def myfunction(self):
try:
#some code
except NoSuchElementException:
print("error appeared")
#take screenshot here
subject = '')
message = (f"""Here is the screeenshot of the error """)
self.sendEmailBOTS(self.errorReportemail, self.errorReportemailpasswd, self.errorReportemail, subject, message)
for mail in self.ccBots:
self.sendEmailBOTS(self.errorReportemail, self.errorReportemailpasswd, mail, subject, message)
def sendEmailBOTS(self, email, password, send_to, subject, message):
print("Sending email to", send_to)
logging.info("Sending email to")
msg = MIMEMultipart()
msg["From"] = email
msg["To"] = send_to
msg["Subject"] = subject
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, send_to, text)
server.quit()
您可以尝试拍摄如下屏幕截图:
相关问题 更多 >
编程相关推荐