#!usr/bin/python3 #-*- coding:utf-8 -*- ##python+selenium自动化33——163发送附件(文件上传) #time:2021-01-06 from selenium import webdriver import time class Send_email_163(): def __init__(self): self.driver = webdriver.Chrome() #定义浏览器 def Login_163(self): self.driver.get("https://mail.163.com/") #获取地址 self.driver.implicitly_wait(10) self.driver.maximize_window() frame = self.driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/div[3]/div[4]/div[1]/div[1]/iframe") #定义登录frame框架 self.driver.switch_to.frame(frame) #切换到登录框架 self.driver.find_element_by_name("email").clear() self.driver.find_element_by_name("email").send_keys("183*******35") #输入账号 self.driver.find_element_by_name("password").clear() self.driver.find_element_by_name("password").send_keys("f**********5.") #输入密码 # driver.switch_to.default_content() #释放iframe框架 self.driver.find_element_by_id("dologin").click() # 登录 time.sleep(5) def Write_163(self): self.driver.find_element_by_xpath("//*[@id='_mail_component_132_132']/span[2]").click() #点击写信按钮 time.sleep(3) # 输入收件人信息 self.driver.find_element_by_class_name("nui-editableAddr-ipt").send_keys("1129718462@qq.com") time.sleep(5) # 输入主题 full_xpath self.driver.find_element_by_xpath( "/html/body/div[2]/div[1]/div[2]/div[1]/section/header/div[2]/div[1]/div/div/input").send_keys("163主题") time.sleep(5) # 上传附件 self.driver.find_element_by_xpath("//input[@type='file' and @class='O0']").send_keys( r"D:\Learning-document\Py_work\Project_3\014切换iframe登录163\login_163.docx") time.sleep(2) # text = driver.find_element_by_class_name("APP-editor-iframe") # self.driver.switch_to.frame(text) self.driver.switch_to.frame(self.driver.find_element_by_xpath("//iframe[contains(@class,'APP-editor-iframe')]")) self.driver.find_element_by_class_name("nui-scroll").send_keys('发送第二封信件') # 可以输入要发送内容 self.driver.switch_to.default_content() #跳出frame框架 time.sleep(5) def Send_163(self): self.driver.find_element_by_xpath("/html/body/div[2]/div[1]/div[2]/div[1]/section/footer/div[1]").click() #点击发送按钮 time.sleep(5) def Quit_163(self): self.driver.quit() if __name__ == '__main__': result = Send_email_163() result.Login_163() result.Write_163() result.Send_163() result.Quit_163()
python+selenium(上传附件并发送邮件)-0106
最新推荐文章于 2022-03-15 19:57:30 发布