@@ -193,6 +193,21 @@ def main():
193
193
seleniumbase_lines .append (command )
194
194
continue
195
195
196
+ # Handle .find_element_by_xpath() + .send_keys()
197
+ data = re .match (
198
+ '''^(\s*)driver\.find_element_by_xpath\(\" ([\S\s]+)\" \)'''
199
+ '''\.send_keys\(\" ([\S\s]+)\" \)\s*$''' , line )
200
+ if data :
201
+ whitespace = data .group (1 )
202
+ css_selector = '%s' % data .group (2 )
203
+ text = data .group (3 )
204
+ command = '''%sself.update_text("%s", '%s')''' % (
205
+ whitespace , css_selector , text )
206
+ if command .count ('\\ "' ) == command .count ('"' ):
207
+ command = command .replace ('\\ "' , '"' )
208
+ seleniumbase_lines .append (command )
209
+ continue
210
+
196
211
# Handle Select / by_css_selector() / select_by_visible_text()
197
212
data = re .match (
198
213
'''^(\s*)Select\(driver\.find_element_by_css_selector\('''
@@ -219,7 +234,7 @@ def main():
219
234
if '(u"' in line :
220
235
uni = "u"
221
236
has_unicode = True
222
- command = '''%sself.click_xpath (%s"%s")''' % (
237
+ command = '''%sself.click (%s"%s")''' % (
223
238
whitespace , uni , xpath )
224
239
seleniumbase_lines .append (command )
225
240
continue
@@ -312,6 +327,24 @@ def main():
312
327
seleniumbase_lines .append (command )
313
328
continue
314
329
330
+ # Handle self.is_element_present(By.CSS_SELECTOR, *)
331
+ data = re .match (
332
+ '''^(\s*)([\S\s]*)self\.is_element_present\(By.CSS_SELECTOR, '''
333
+ '''u?\" ([\S\s]+)\" \)([\S\s]*)$''' , line )
334
+ if data :
335
+ whitespace = data .group (1 )
336
+ pre = data .group (2 )
337
+ css_selector = '''%s''' % data .group (3 )
338
+ post = data .group (4 )
339
+ uni = ""
340
+ if '(u"' in line :
341
+ uni = "u"
342
+ has_unicode = True
343
+ command = '''%s%sself.is_element_present("%s")%s''' % (
344
+ whitespace , pre , css_selector , post )
345
+ seleniumbase_lines .append (command )
346
+ continue
347
+
315
348
# Handle self.is_element_present(By.XPATH, *)
316
349
data = re .match (
317
350
'''^(\s*)([\S\s]*)self\.is_element_present\(By.XPATH, '''
@@ -392,6 +425,50 @@ def main():
392
425
seleniumbase_lines .append (line )
393
426
continue
394
427
428
+ # Remove duplicate functionality (wait_for_element)
429
+ lines = seleniumbase_lines
430
+ seleniumbase_lines = []
431
+ num_lines = len (lines )
432
+ for line_num in range (len (lines )):
433
+ data = re .match ('''^\s*self.wait_for_element'''
434
+ '''\((["|'])([\S\s]+)(["|'])\)'''
435
+ '''\s*$''' , lines [line_num ])
436
+ if data :
437
+ # quote_type = data.group(1)
438
+ selector = data .group (2 )
439
+ if int (line_num ) < num_lines - 1 :
440
+ regex_string = (r'''^\s*self.click\(["|']'''
441
+ + re .escape (selector ) + r'''["|']\)\s*$''' )
442
+ data2 = re .match (regex_string , lines [line_num + 1 ])
443
+ if data2 :
444
+ continue
445
+ regex_string = (r'''^\s*self.update_text\(["|']'''
446
+ + re .escape (selector )
447
+ + r'''["|'], [\S\s]+\)\s*$''' )
448
+ data2 = re .match (regex_string , lines [line_num + 1 ])
449
+ if data2 :
450
+ continue
451
+ seleniumbase_lines .append (lines [line_num ])
452
+
453
+ # Remove duplicate functionality (wait_for_link_text)
454
+ lines = seleniumbase_lines
455
+ seleniumbase_lines = []
456
+ num_lines = len (lines )
457
+ for line_num in range (len (lines )):
458
+ data = re .match ('''^\s*self.wait_for_link_text'''
459
+ '''\((["|'])([\S\s]+)(["|'])\)'''
460
+ '''\s*$''' , lines [line_num ])
461
+ if data :
462
+ # quote_type = data.group(1)
463
+ link_text = data .group (2 )
464
+ if int (line_num ) < num_lines - 2 :
465
+ regex_string = (r'''^\s*self.click_link_text\(["|']'''
466
+ + re .escape (link_text ) + r'''["|']\)\s*$''' )
467
+ data2 = re .match (regex_string , lines [line_num + 1 ])
468
+ if data2 :
469
+ continue
470
+ seleniumbase_lines .append (lines [line_num ])
471
+
395
472
seleniumbase_code = ""
396
473
if has_unicode :
397
474
seleniumbase_code = "# -*- coding: utf-8 -*-\n "
0 commit comments