Python Selenium nosetest utf-8 issues resolved for non standard characters

Had some trouble recently testing with some non standard characters, mainly “ and ”

I originally had this line in the Python code:

self.assertEqual(self.driver.find_element_by_xpath("html/body/example").text,"and then comes “special text” in the UI", msg=None)

When running this script, an error would be returned:

SyntaxError: Non-ASCII character '\xe2' in file 

I had to add this to the top of the Python files

# coding=UTF-8

So now the Python (Selenium) script was running fine. However, when I tried to test with nose (nosetest) I got a different error:

AssertionError: u'and then comes \u201cspecial text\u201d in the UI' != 'and then comes \xe2\x80\x9cspecial text\xe2\x80\x9d in the UI'

soooo, then I added a decode at the end of the questionable string like this:

self.assertEqual(self.driver.find_element_by_xpath("html/body/example").text,"and then comes “special text” in the UI".decode('utf-8'), msg=None)

and it magically worked.

Save button grayed out (resolved) when setting proxy to manual on Android device (Nexus, LG Optimus)

I have not been able to find the resolution to this issue anywhere. Finally figured it out.

On multiple Android devices I was able to set the manual proxy simply by accessing the advanced network settings and saving the new values. However, on several Androids, the Save button was always grayed out.

All you need to do is populate the Wifi network password field as well. Then the Save button will not be grayed out. So each time you need to update these, first populate the password field, then change the proxy settings, IP, port etc. and it just might resolve your issue.

Save button grayed out (resolved) when setting proxy to manual on Android device (Nexus, LG Optimus)

Replace (Select) All except a string with Regex and Notepad++

This worked for me. I could not really find the full expression anywhere so here it is. It works with Notepad++ 6.1.5 . I know for a fact that it does not work with some other regular expression implementations.

Let’s say you have a bunch of text and you want Notepad++ to replace (select) all of the text except the string blahblah.
Open the Replace tool (Ctrl+H).
In the “Find what” field enter this:

(?<=blahblah)(.+)|(.+)(?=blahblah)|^((?!blahblah).)*$

Do not enter anything in the "Replace with" field if you want to remove everything except blahblah
Make sure that you also select the "Regular expression" radio button at the bottom of the Replace window.
Click on "Replace All" ...
Voila, you should have only the blahblah text left.

If you would like to remove everything except 5 digit numbers, you could do this:

(?<=[0-9]{5})(.+)|(.+)(?=[0-9]{5})|^((?![0-9]{5}).)*$

There is an explanation for this:

(?<=blahblah)(.+)

removes all characters after string blahblah to the end of the line (in lines that contain the blahblah string).

(.+)(?=blahblah)

removes all characters before string blahblah from the beginning of the line (in lines that contain the blahblah string).

^((?!blahblah).)*$

marks all lines that do not contain string blahblah

These are piped together with "|".

Is this the best way to do this? Most likely not, but it does get the job done and I did not see it documented elsewhere.

This post on stackoverflow.com definitely helped.