Python+selenium自动循环扔QQ邮箱漂流瓶

Python代码如下:

# coding=utf-8
from selenium import webdriver
from time import sleep
from random import randint

def auto_throw():
    """扔瓶子"""
    driver = webdriver.Chrome()
    driver.get("https://mail.qq.com")
    sleep(2)
    # 切换iframe表单
    driver.switch_to.frame("login_frame")
    driver.find_element_by_xpath('//*[@id="u"]').send_keys("")
    driver.find_element_by_xpath('//*[@id="p"]').send_keys("cb19939393")
    driver.find_element_by_xpath('//*[@id="login_button"]').click()
    # 将表单切回到最外层
    driver.switch_to.default_content()
    sleep(2)
    i = 0
    m =# 循环扔瓶子
    while True:
        try:
            driver.find_element_by_xpath('//*[@id="folder_11"]/b[1]').click()  # 漂流瓶
            sleep(1)
            # 切换iframe表单
            driver.switch_to.frame("mainFrame")
            sleep(1)
            driver.find_element_by_xpath('//*[@id="toolbar"]/div/a[1]').click()    # 扔一个
            sleep(1)
            driver.find_element_by_xpath('//*[@id="bottle_magic"]/div/div[1]/a[1]/span').click()     # 普通瓶
            sleep(1)
            driver.find_element_by_xpath('//*[@id="bottle_send"]/div[2]/div[1]/div[4]/div[2]/div[1]/textarea').send_keys("陌生人,<br />                                                                                              你的幸运数字是%d!"%randint(1,10000))
            sleep(2)
            driver.find_element_by_xpath('//*[@id="bottle_send"]/div[2]/div[2]/div[3]/a[2]').click()      # 扔出去
            # 将表单切回到最外层
            driver.switch_to.default_content()
            m += 1
            print("第%d个瓶子成功扔出!"%m)
            sleep(2)
        except:
            print("扔瓶子失败或者扔瓶子机会用完了!")
            i += 1
            if i > 10:
                print("扔瓶子机会用完了!")
                break


if __name__ == '__main__':
    auto_throw()