@@ -66,7 +66,9 @@ def test_anything(self):
66
66
logging .getLogger ("urllib3" ).setLevel (logging .ERROR )
67
67
urllib3 .disable_warnings ()
68
68
LOGGER .setLevel (logging .WARNING )
69
+ python3 = True
69
70
if sys .version_info [0 ] < 3 :
71
+ python3 = False
70
72
reload (sys ) # noqa: F821
71
73
sys .setdefaultencoding ("utf8" )
72
74
selenium4 = False
@@ -144,9 +146,8 @@ def open(self, url):
144
146
pre_action_url = self .driver .current_url
145
147
except Exception :
146
148
pass
147
- if type (url ) is str :
148
- url = url .strip () # Remove leading and trailing whitespace
149
- if (type (url ) is not str ) or not self .__looks_like_a_page_url (url ):
149
+ url = str (url ).strip () # Remove leading and trailing whitespace
150
+ if not self .__looks_like_a_page_url (url ):
150
151
# url should start with one of the following:
151
152
# "http:", "https:", "://", "data:", "file:",
152
153
# "about:", "chrome:", "opera:", or "edge:".
@@ -742,7 +743,7 @@ def refresh(self):
742
743
def get_current_url (self ):
743
744
self .__check_scope ()
744
745
current_url = self .driver .current_url
745
- if "%" in current_url and sys . version_info [ 0 ] >= 3 :
746
+ if "%" in current_url and python3 :
746
747
try :
747
748
from urllib .parse import unquote
748
749
@@ -2386,6 +2387,8 @@ def open_html_file(self, html_file):
2386
2387
def execute_script (self , script , * args , ** kwargs ):
2387
2388
self .__check_scope ()
2388
2389
self .__check_browser ()
2390
+ if not python3 :
2391
+ script = unicode (script .decode ('latin-1' )) # noqa: F821
2389
2392
return self .driver .execute_script (script , * args , ** kwargs )
2390
2393
2391
2394
def execute_async_script (self , script , timeout = None ):
@@ -2520,6 +2523,8 @@ def set_content_to_frame(self, frame, timeout=None):
2520
2523
url = self .execute_script (
2521
2524
"""return document.querySelector('%s').src;""" % frame
2522
2525
)
2526
+ if not python3 :
2527
+ url = str (url )
2523
2528
if url and len (url ) > 0 :
2524
2529
if ("http:" ) in url or ("https:" ) in url or ("file:" ) in url :
2525
2530
pass
@@ -3547,7 +3552,7 @@ def __process_recorded_actions(self):
3547
3552
cleaned_actions .append (srt_actions [n ])
3548
3553
for action in srt_actions :
3549
3554
if action [0 ] == "begin" or action [0 ] == "_url_" :
3550
- if "%" in action [2 ] and sys . version_info [ 0 ] >= 3 :
3555
+ if "%" in action [2 ] and python3 :
3551
3556
try :
3552
3557
from urllib .parse import unquote
3553
3558
@@ -3556,7 +3561,7 @@ def __process_recorded_actions(self):
3556
3561
pass
3557
3562
sb_actions .append ('self.open("%s")' % action [2 ])
3558
3563
elif action [0 ] == "f_url" :
3559
- if "%" in action [2 ] and sys . version_info [ 0 ] >= 3 :
3564
+ if "%" in action [2 ] and python3 :
3560
3565
try :
3561
3566
from urllib .parse import unquote
3562
3567
@@ -10464,7 +10469,7 @@ def __recalculate_selector(self, selector, by, xp_ok=True):
10464
10469
used to make the ":contains()" selector valid outside JS calls."""
10465
10470
_type = type (selector ) # First make sure the selector is a string
10466
10471
not_string = False
10467
- if sys . version_info [ 0 ] < 3 :
10472
+ if not python3 :
10468
10473
if _type is not str and _type is not unicode : # noqa: F821
10469
10474
not_string = True
10470
10475
else :
@@ -11123,7 +11128,7 @@ def __set_last_page_source(self):
11123
11128
def __get_exception_info (self ):
11124
11129
exc_message = None
11125
11130
if (
11126
- sys . version_info [ 0 ] >= 3
11131
+ python3
11127
11132
and hasattr (self , "_outcome" )
11128
11133
and (hasattr (self ._outcome , "errors" ) and self ._outcome .errors )
11129
11134
):
@@ -11234,11 +11239,11 @@ def __has_exception(self):
11234
11239
has_exception = False
11235
11240
if hasattr (sys , "last_traceback" ) and sys .last_traceback is not None :
11236
11241
has_exception = True
11237
- elif sys . version_info [ 0 ] >= 3 and hasattr (self , "_outcome" ):
11242
+ elif python3 and hasattr (self , "_outcome" ):
11238
11243
if hasattr (self ._outcome , "errors" ) and self ._outcome .errors :
11239
11244
has_exception = True
11240
11245
else :
11241
- if sys . version_info [ 0 ] >= 3 :
11246
+ if python3 :
11242
11247
has_exception = sys .exc_info ()[1 ] is not None
11243
11248
else :
11244
11249
if not hasattr (self , "_using_sb_fixture_class" ) and (
@@ -11247,7 +11252,10 @@ def __has_exception(self):
11247
11252
has_exception = sys .exc_info ()[1 ] is not None
11248
11253
else :
11249
11254
has_exception = len (str (sys .exc_info ()[1 ]).strip ()) > 0
11250
- if hasattr (self , "_using_sb_fixture" ) and self .__will_be_skipped :
11255
+ if (
11256
+ self .__will_be_skipped
11257
+ and (hasattr (self , "_using_sb_fixture" ) or not python3 )
11258
+ ):
11251
11259
has_exception = False
11252
11260
return has_exception
11253
11261
0 commit comments