**注意点:**:1、延时:防止长时间未加载完成,程序运行2、iframe框架切换,不然会定位不到元素import tracebackfrom selenium import webdriverimport timebro = webdriver.Chrome()bro.get('/')def main():try:time.sleep(3)# 切换到登录的iframe,不然会找不到元素iframe = bro.find_element_by_xpath('//div[@id="loginDiv"]/iframe')bro.switch_to_frame(iframe)time.sleep(2)# 输入账号bro.find_element_by_name('email').clear()bro.find_element_by_name('email').send_keys(账号)time.sleep(1)# 输入密码bro.find_element_by_name('password').clear()bro.find_element_by_name('password').send_keys(密码)# 登录,切换回默认iframetime.sleep(1)bro.find_element_by_id('dologin').click()bro.switch_to_default_content()# 退出功能# bro.find_element_by_partial_link_text('退出').click()# 找到写信按钮time.sleep(1)bro.find_element_by_xpath('//b[@class="nui-ico fn-bg ga0"]').click()time.sleep(2)# 找到收件人bro.find_element_by_xpath('//input[@class="nui-editableAddr-ipt"]').send_keys(收件人)time.sleep(1)# 主题bro.find_element_by_xpath('//input[@class="nui-ipt-input" and @maxlength="256"]').send_keys('selenium测试')time.sleep(1)# 添加附件ele = bro.find_element_by_xpath('//div[@class="by0"]/input[@class="O0"]')ele.send_keys(r'D:\new.txt')time.sleep(1)# 要发送内容,需要切换到写信内容的iframe里ele1 = bro.find_element_by_class_name('APP-editor-iframe')bro.switch_to_frame(ele1)bro.find_element_by_xpath('/html/body').send_keys('selenium测试邮件')# 发送邮件# 切回默认iframetime.sleep(2)bro.switch_to_default_content()bro.find_element_by_xpath('//*[@class="jp0"]/div[@role="button"][1]').click()except Exception:print(traceback.print_exc())if __name__ == '__main__':main()
100字范文,内容丰富有趣,生活中的好帮手!