Get Source, Create File, Get File gives UTF-8 decoding error

87 views
Skip to first unread message

Claes

unread,
Jan 26, 2009, 10:36:12 AM1/26/09
to robotframework-users
I wanted to try the following
1) Get source from web page
2) Save source to file
3) Get file
4) Compare saved file to source

Step 3 fails with error message utf-8 decoding error: invalid data.
(I'm running my tests on Windows Vista.)

My question: What am I doing wrong? How can I get this to work?

** Test Case **
Compare saved page to current page Open browser https://www.google.com
*firefox
${currentPage}= Get Source
Create File ${TEMPDIR}${/}google-page1.html ${currentPage}
${savedPage}= Get File ${TEMPDIR}${/}google-page1.html
Should Be Equal as Strings ${savedPage} ${currentPage}
Close Browser

** Result **
KEYWORD: ${savedPage} = OperatingSystem.Get File ${TEMPDIR}${/}google-
page1.html
Documentation: Returns the contents of a specified file.
Start / End / Elapsed: 20090126 16:00:26.391 / 20090126
16:00:26.420 / 00:00:00.029
16:00:26.397 INFO Getting file 'C:\Users\CLAPIP~1.OME\AppData\Local
\Temp\google-page1.html'
16:00:26.417 FAIL UnicodeError: utf-8 decoding error: invalid data

Pekka Klärck

unread,
Jan 26, 2009, 10:53:08 AM1/26/09
to claes...@gmail.com, robotframework-users
2009/1/26 Claes <claes...@gmail.com>:

>
> I wanted to try the following
> 1) Get source from web page
> 2) Save source to file
> 3) Get file
> 4) Compare saved file to source
>
> Step 3 fails with error message utf-8 decoding error: invalid data.
> (I'm running my tests on Windows Vista.)
>
> My question: What am I doing wrong? How can I get this to work?

My guess is that
1) The source you get has some other encoding than ASCII or UTF-8
2) Create File uses that encoding when writing the file (it doesn't
even accept encoding)
3) Get File uses UTF-8 encoding when reading the file (that's the default)
=> UnicodeDecodeError

You can test is my guess valid either by
- specifying a correct encoding to Get File (you should see it in the
source and the default is ISO-8859-1), or
- changing Create File to encode the given text by changing
"f.write(content)" to "f.write(content.encode('UTF-8')".

If I'm right, then the correct fix for this is adding encoding
argument to Create File keyword.

Cheers,
.peke

Claes

unread,
Jan 26, 2009, 11:00:18 AM1/26/09
to robotframework-users
Inside the file I find

<head><meta http-equiv="content-type" content="text/html;
charset=UTF-8"><title>Google</title>

So it seems the file is UTF-8 encoded. Or?

/Claes

On 26 Jan, 16:53, Pekka Klärck <p...@iki.fi> wrote:
> 2009/1/26 Claes <claes.pi...@gmail.com>:

Pekka Klärck

unread,
Jan 26, 2009, 11:06:32 AM1/26/09
to claes...@gmail.com, robotframework-users
2009/1/26 Claes <claes...@gmail.com>:

>
> Inside the file I find
>
> <head><meta http-equiv="content-type" content="text/html;
> charset=UTF-8"><title>Google</title>
>
> So it seems the file is UTF-8 encoded. Or?

It should be UTF-8. Then the problem could also be that Get Source
doesn't decode the source correctly. Could you submit a but about this
either to Robot Framework or SeleniumLibrary issue tracker? If you
have a simple example that uses a public website it would help us
investigating it furthers.

I'll add a separate issue about Create File needing 'encode' argument.

Cheers,
.peke

Message has been deleted

Claes

unread,
Jan 26, 2009, 11:57:26 AM1/26/09
to robotframework-users

Sujata Dwivedi

unread,
Apr 11, 2013, 4:09:14 PM4/11/13
to robotframe...@googlegroups.com
Hi,

How you save this html source code which you get from get source command into any file.

Thanks
Reply all
Reply to author
Forward
0 new messages