@@ -87,14 +87,28 @@ def main():
87
87
continue
88
88
89
89
# Handle page loads
90
- data = re .findall (
91
- '^\s*driver\.get\(self\.base_url \+ \" /\" \)\s*$' , line )
90
+ data = re .match (
91
+ '^( \s*) driver\.get\(( self\.base_url \+ \" /\S* \" ) \)\s*$' , line )
92
92
if data :
93
- data = data [0 ].replace ("self.base_url" , '"%s"' % ide_base_url )
94
- if ' + "/"' in data :
95
- data = data .replace (' + "/"' , '' )
96
- data = data .replace ('driver.get(' , 'self.open(' )
97
- seleniumbase_lines .append (data )
93
+ whitespace = data .group (1 )
94
+ url = data .group (2 )
95
+ url = url .replace ("self.base_url" , '"%s"' % ide_base_url )
96
+ if '/" + "/' in url :
97
+ url = url .replace ('/" + "/' , '/' )
98
+ if "/' + '/" in url :
99
+ url = url .replace ("/' + '/" , "/" )
100
+ command = '''%sself.open(%s)''' % (whitespace , url )
101
+ seleniumbase_lines .append (command )
102
+ continue
103
+
104
+ # Handle more page loads
105
+ data = re .match (
106
+ '^(\s*)driver\.get\(\" (\S*)\" \)\s*$' , line )
107
+ if data :
108
+ whitespace = data .group (1 )
109
+ url = data .group (2 )
110
+ command = '''%sself.open('%s')''' % (whitespace , url )
111
+ seleniumbase_lines .append (command )
98
112
continue
99
113
100
114
# Handle .find_element_by_id() + .click()
@@ -220,11 +234,13 @@ def main():
220
234
seleniumbase_lines .append (command )
221
235
continue
222
236
237
+ # Replace "self.base_url" with actual url if not already done
238
+ if 'self.base_url' in line :
239
+ line = line .replace ("self.base_url" , '"%s"' % ide_base_url )
240
+
223
241
# Convert driver. to self.driver. if not already done
224
242
if 'driver.' in line and 'self.driver' not in line :
225
- command = line .replace ('driver.' , 'self.driver.' )
226
- seleniumbase_lines .append (command )
227
- continue
243
+ line = line .replace ('driver.' , 'self.driver.' )
228
244
229
245
# Add all other lines to final script without making changes
230
246
seleniumbase_lines .append (line )
@@ -243,6 +259,8 @@ def main():
243
259
out_file = codecs .open (converted_file_name , "w+" )
244
260
out_file .writelines (seleniumbase_code )
245
261
out_file .close ()
262
+ print ("%s successfully created from %s\n " % (
263
+ converted_file_name , webdriver_python_file ))
246
264
247
265
248
266
if __name__ == "__main__" :
0 commit comments