from time import sleep标签:qq,selenium,driver,element,sleep,邮箱,ID,find From: https://www.cnblogs.com/creeperrr/p/17219317.html
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("detach", True)
# 打开谷歌浏览器
driver = webdriver.Chrome(options=options)
# 创建浏览器实例
# 打开网页
driver.get("https://mail.qq.com/")
# 等待页面加载完成
sleep(5)
# 切换到iframe中
iframe = driver.find_element(By.ID, "login_frame")
driver.switch_to.frame(iframe)
#手动扫码
driver.find_element(By.ID,"switcher_qlogin").click()
sleep(10)
# # 输入用户名和密码登录
# driver.find_element(By.ID, "u").send_keys("")
# driver.find_element(By.ID, "p").send_keys("")
# driver.find_element(By.ID, "login_button").click()
# 等待页面加载完成
sleep(10)
# 点击写信
driver.find_element(By.CSS_SELECTOR,"#composebtn_td").click()
# 定位收件人并输入收件人信息
sleep(3)
driver.switch_to.frame('mainFrame')
print("跳转成功")
driver.find_element(By.XPATH,"//*[@id='toAreaCtrl']/div[2]/input").send_keys("[email protected]")
# 上传附件(这里需要自己修改文件路径)
driver.find_element(By.NAME,"UploadFile").send_keys("C:/Users/Administrator/Desktop/1.txt")
# 定位发送并点击
driver.find_element(By.XPATH,'//*[@id="toolbar"]/div[1]/a[1]').click()
print("发送成功")
# 等待发送完成
sleep(5)
# 关闭浏览器
# driver.quit()