1

I'm trying to write a code that automatically logs into two websites and goes to a certain page. I use Splinter.

I only get the error with the "Mijn ING Zakelijk" website using PhantomJS as browser type.

Until a few days ago the code ran perfectly fine 20 out of 20 times. But since today I'm getting an error. Sometimes the code runs fine. Other times it does not and gives me the "Click succeeded but Load Failed.." error. Here's the full traceback:

## Attempting to login to Mijn ING Zakelijk, please wait.
- Starting the browser..
- Visiting the url..
- Filling the username form with the defined username..
- Filling the password form with the defined password..
- Clicking the submit button..
Traceback (most recent call last):
  File "/Users/###/Dropbox/Python/Test environment 2.7.3/Splinter.py", line 98, in <module>
    mijning()
  File "/Users/###/Dropbox/Python/Test environment 2.7.3/Splinter.py", line 27, in mijning
    attemptLogin(url2, username2, password2, defined_title2, website_name2, browser_type2)
  File "/Users/###/Dropbox/Python/Test environment 2.7.3/Splinter.py", line 71, in attemptLogin
    browser.find_by_css('.submit').first.click()
  File "/Users/###/Library/Python/2.7/lib/python/site-packages/splinter/driver/webdriver/__init__.py", line 344, in click
    self._element.click()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 54, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 228, in _execute
    return self._parent.execute(command, params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 158, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'Error Message => \'Click succeeded but Load Failed. Status: \'fail\'\'\n caused by Request => {"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"81","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:56899","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\\"sessionId\\": \\"c2bbc8a0-e3d2-11e2-b7a8-f765797dc4e7\\", \\"id\\": \\":wdc:1372850513087\\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/c2bbc8a0-e3d2-11e2-b7a8-f765797dc4e7/element/%3Awdc%3A1372850513087/click"}' ; Screenshot: available via screen 

Process finished with exit code 1

Here's the full code:

## *** Payment Notification and Mail Tool (FPNMT) ##
from splinter import *
from Tkinter import *

def ###():

    # Define values
    browser_type1 = 'phantomjs' # 'phantomjs' or 'firefox'
    url1 = 'http://###.nl/admin'
    username1 = '###'
    password1 = '###'
    defined_title1 = 'Bestellingen'
    website_name1 = '###.nl Admin'

    attemptLogin(url1, username1, password1, defined_title1, website_name1, browser_type1)

def mijning():

    # Define values
    browser_type2 = 'phantomjs' # 'phantomjs' or 'firefox'
    url2 = 'https://mijnzakelijk.ing.nl/internetbankieren/SesamLoginServlet'
    username2 = '###'
    password2 = '###'
    defined_title2 = 'Saldo informatie'
    website_name2 = 'Mijn ING Zakelijk'

    attemptLogin(url2, username2, password2, defined_title2, website_name2, browser_type2)

# Functions #
def attemptLogin(url, username, password, defined_title, website_name, browser_type):
    print '## Attempting to login to ' + website_name + ', please wait.'

    # Start the browser
    print '- Starting the browser..'
    browser = Browser(browser_type)

    # Visit in the url
    print '- Visiting the url..'
    browser.visit(url)

    if website_name == '###.nl Admin':
        # Find the username form and fill it with the defined username
        print '- Filling the username form with the defined username..'
        browser.fill('username', username)

        # Find the password form and fill it with the defined password
        print '- Filling the password form with the defined password..'
        browser.fill('password', password)

        # Find the submit button and click
        print '- Clicking the submit button..'
        browser.click_link_by_text('Inloggen')

        # Find, click and display page with order history
        print '- Visiting the defined web page..'
        current_token = browser.url[57:97]
        url_plus_token = 'http://www.###.nl/admin/index.php?route=sale/order' + current_token
        browser.visit(url_plus_token)

    else:
        website_name == 'Mijn ING Zakelijk'
        # Find the username form and fill it with the defined username
        print '- Filling the username form with the defined username..'
        browser.find_by_id('gebruikersnaam').first.find_by_tag('input').fill(username)

        # Find the password form and fill it with the defined password
        print '- Filling the password form with the defined password..'
        browser.find_by_id('wachtwoord').first.find_by_tag('input').fill(password)

        # Find the submit button and click
        print '- Clicking the submit button..'
        browser.find_by_css('.submit').first.click()

        # Display page with transaction history
        print '- Visiting the defined web page..'
        browser.visit('https://mijnzakelijk.ing.nl/mpz/solstartpaginarekeninginfo.do')

    # Get page title after successful login
    current_title = browser.title

    # Check the title of the page to confirm successful login
    checkLogin(defined_title, current_title, website_name, browser)

def checkLogin(defined_title, current_title, website_name, browser):
    if current_title == defined_title:
        print '# Login to', website_name, 'successful.'
        print '- Quitting the browser..'
        browser.quit()

    else:
        print '# Login to', website_name, 'failed.'
        print '- Quitting the browser..'
        browser.quit()

i = 1
while i < 10:
    print i
    #***()
    mijning()
    i = i+1

Any ideas on what's causing this error and how do I solve it?

Thanks.

narzero
  • 2,199
  • 5
  • 40
  • 73

3 Answers3

5

The current version of the ghostdriver source code fixes the issue (there is no longer any "Click succeeded but Load Failed" message" - see here). The thing is, that version is not yet released (as of 08/19/2013), so you need to get it and then build it yourself. That solved the problem for me (Windows 7, Python 2.7.5, Selenium 2.33). You can find the step-by-step here.

UPDATE:

PhantomJS 1.9.2 just came out and with Ghostdriver 1.0.4, which fixes the problem (check here - no more "Click succeeded but Load Failed" message). So just upgrade to PhantomJS 1.9.2 and you should be fine. No need to build anything yourself anymore.

Parzival
  • 2,004
  • 4
  • 33
  • 47
  • Hi, i'm having trouble building the binary on windows(it quits half-way through due to some error), is there someplace you can upload the binary to? It'd be much appreciated. – raphonic Sep 07 '13 at 12:15
  • http://speedy.sh/evF2a/phantomjs.exe I tested with Windows 7 Home Premium and Windows 7 Enterprise and it worked in both cases. – Parzival Sep 07 '13 at 16:47
  • Thanks a lot. I'm running Windows 8 pro, and it works fine here too. – raphonic Sep 09 '13 at 04:57
  • Version 1.9.2 just came out (http://phantomjs.org/download.html). It should work right out of the box now, no need to compile it ourselves anymore. – Parzival Sep 16 '13 at 02:05
2

It may be that there was already some active javascript or background AJAX on the page, which confused PhantomJS into thinking that button click was unsuccessful. You could try inserting wait or try to stop the browser before clicking.

Furious Duck
  • 2,009
  • 1
  • 16
  • 18
  • I can't seem to find a way to wait, stop or pauze the browser. I tried "wait_time=10" but I don't think it has any effect and actually stops te browser for 10 seconds before clicking. How can I stop/pauze the browser? – narzero Jul 03 '13 at 13:02
  • Try `import time` and `time.sleep(10)` before clicking. You're using python after all ;) – Furious Duck Jul 03 '13 at 13:37
  • Thanks a lot Alexander! This solved it. 20 out of 20 login attempts were successful. – narzero Jul 03 '13 at 14:16
0

This is a fixed bug, but it's show in some actual pages.

A workaround:

public static void ClickAndWaitStale( this IWebElement element , DateTime limit = default(DateTime) , TimeSpan sleepBetween = default(TimeSpan) )
{
    if ( limit == default(DateTime) )
        limit = DateTime.Now.AddSeconds( 300 );
    if ( sleepBetween == default(TimeSpan ) )
        sleepBetween = TimeSpan.FromSeconds( 1 );

    try
    {
        element.Click();
    }
    catch ( System.InvalidOperationException ) // Click succeeded but Load Failed
    {
    }

    while ( DateTime.Now < limit )
    {
        try
        {
            element.GetAttribute( "id" );
            Thread.Sleep( sleepBetween );
        }
        catch ( StaleElementReferenceException )
        {
            return;
        }
    }
    throw new TimeoutException( "Timeout waiting for stale object." );
}