栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

通过Pycharm发送邮件

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过Pycharm发送邮件

第一次发博客,...登录步骤就直接省略掉了,定位元素写得有点长,没办法,比较菜...哈哈哈

# 1.导入selenium
from selenium import webdriver
import os
import time
# 2.添加个人资料路径
user_data = r"--user-data-dir=C:UsersadminAppDataLocalGoogleChromeUser Data"
# 3.将个人资料路径添加到谷歌浏览器加载项中
options = webdriver.ChromeOptions()
options.add_argument(user_data)
# 4.带着加载项打开谷歌浏览器
driver = webdriver.Chrome(options=options)
# 5.访问126邮箱并窗口最大化
driver.get("https://www.126.com/")
driver.maximize_window()
time.sleep(3)
# 6.点击写信
driver.find_element_by_xpath("//li[@id='_mail_component_149_149']/span[2]").click()
time.sleep(3)
# 7.定位收件人,填写收件人并确认收件人
driver.find_element_by_class_name("nui-editableAddr-ipt").send_keys("xxxx@163.com")
# driver.find_element_by_class_name("nui-menu-item-text").click()
time.sleep(3)
# 8.定位主题并填写主题
theme_send = driver.find_element_by_xpath("//div[@id='_dvModuleContainer_compose.ComposeModule_0']/div/section/header/div[2]/div/div/div/input")
theme_send.send_keys("XXXXX")
time.sleep(3)
# 9.上传文件
# 9.1 定位文件上传按钮
button = driver.find_element_by_xpath("//div[@id='_dvModuleContainer_compose.ComposeModule_0']/div/section/header/div[3]/div/div[2]/input")
# 9.2 上传文件的路径
file_up = os.path.abspath("xxx.txt")
# 9.3 上传文件
button.send_keys(file_up)
# 10.定位发送并点击
send_file = driver.find_element_by_xpath("//div[@id='_dvModuleContainer_compose.ComposeModule_0']/div/section/footer/div/span[2]")
send_file.click()
# 11.关闭浏览器
time.sleep(5)
driver.quit()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/934112.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号