简体   繁体   中英

Why does python.exe crash when I run this Selenium/WebDriver code using IE as the driver?

I've got IE 9 on Windows 7 and Python 2.7. This code runs perfectly when I use Firefox for the driver, but with IE it crashes after a few seconds. I wonder if it's hitting a high CPU state during the while loop? I am a noob when it comes to writing good while/wait loops.

def text_from_gmail(username, password, to_user, pattern):
    gmail = PyGmail('imap.gmail.com')
    gmail.login(username, password)

    #find the id of the confirmation message
    sec_waiting = 0
    msg_uid = ['']
    sleep_period = 10  # seconds to wait between Gmail searches
    while msg_uid == ['']:  # wait until message list from server isn't empty
        gmail.m.select('[Gmail]/All Mail')
        resp, msg_uid = gmail.m.search(None, 'To', to_user)
        if(msg_uid != ['']):
            break  # don't sleep if the message was found quickly
        time.sleep(sleep_period)  # pause between checks
        sec_waiting += sleep_period
        if sec_waiting >= 300:  # 5 minute timeout
            assert False  # fail the test if timeout elapses

    # extract the confirmation link from the message
    # it's a multi-part MIME, so we have to grab the attachment and decode it
    typ, msg_data = gmail.m.fetch(msg_uid[0], '(RFC822)')
    gmail.logout()
    email_body = msg_data[0][1]
    mail = email.message_from_string(email_body)
    body = ""
    for part in mail.walk():
        if(part.get_content_type() == 'text/plain'):
            body = part.get_payload(decode=True)

    link = re.findall(pattern, body)
    return link

It was trying to go to a malformed URL I think. I put a str() around it driver.web.get(str(confirm_link)) and it's not crashing now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM