@@ -47,23 +47,30 @@ def tearDown(self):
4747
4848 def test_demo1 (self ):
4949 wait = WebDriverWait (self .driver , 10 )
50- actions = ActionChains (self .driver )
50+ # Store window handle
51+ main_window_handle = self .driver .current_window_handle
5152
5253 # Click on element with link text 'Create New'
5354 wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "Create New" ))).click ()
5455
55- time .sleep (1 )
56- # Wait until the popup is loaded and click on the help link
56+ time .sleep (2 )
5757 wait .until (
58- EC .presence_of_element_located ((By .CSS_SELECTOR , 'input[name="keyword"] + roundup-classhelper' ))
58+ EC .element_to_be_clickable ((By .CSS_SELECTOR , 'input[name="keyword"] + roundup-classhelper' ))
5959 ).click ()
6060
6161 # Switch to the new window
62- handles = self .driver .window_handles
63- self .driver .switch_to .window (handles [- 1 ])
62+ # Switch to the popup window
63+ popup_opened = False
64+ while (not popup_opened ):
65+ for handle in self .driver .window_handles :
66+ if handle != main_window_handle :
67+ self .driver .switch_to .window (handle )
68+ popup_opened = True
69+ break ;
6470
6571 # Click on another elements in the new window
66- rows = self .driver .find_elements (By .CSS_SELECTOR , ".row-style" )
72+ tbody = wait .until (EC .presence_of_element_located ((By .CSS_SELECTOR , ".popup-table > tbody" )))
73+ rows = tbody .find_elements (By .CSS_SELECTOR , "tr" )
6774
6875 selected_keywords = []
6976
@@ -72,9 +79,10 @@ def test_demo1(self):
7279 selected_keywords .append (row .get_attribute ("data-id" ))
7380
7481 # unselect row
75- random_number = randint (0 , len (rows ) - 1 )
76- rows [random_number ].find_element (By .TAG_NAME , "input" ).click ()
77- selected_keywords .remove (rows [random_number ].get_attribute ("data-id" ))
82+ if (len (rows )) > 0 :
83+ random_number = randint (0 , len (rows ) - 1 )
84+ rows [random_number ].find_element (By .TAG_NAME , "input" ).click ()
85+ selected_keywords .remove (rows [random_number ].get_attribute ("data-id" ))
7886
7987 preview_values = self .driver .find_element (By .ID , "popup-preview" ).get_attribute ("value" )
8088
@@ -84,7 +92,7 @@ def test_demo1(self):
8492 time .sleep (1 )
8593
8694 # Switch back to the main window
87- self .driver .switch_to .window (handles [ 0 ] )
95+ self .driver .switch_to .window (main_window_handle )
8896
8997 # Wait until the new page is loaded
9098 keyword_value = wait .until (
@@ -379,23 +387,29 @@ def tearDown(self):
379387 self .driver .quit ()
380388
381389 def testFunctionality (self ):
382- wait = WebDriverWait (self .driver , 10 )
390+ wait = WebDriverWait (self .driver , 100 )
383391 actions = ActionChains (self .driver )
392+ # Store window handle
393+ main_window_handle = self .driver .current_window_handle
384394
385395 # Click on element with link text 'Create New'
386396 wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "Create New" ))).click ()
387397
388398 # Click on element with link text '(list)'
389399 wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "(list)" ))).click ()
390400
391- # Store window handle
392- main_window_handle = self .driver .current_window_handle
393401 # Switch to the popup window
394- self .driver .switch_to .window (self .driver .window_handles [- 1 ])
395-
402+ popup_opened = False
403+ while (not popup_opened ):
404+ for handle in self .driver .window_handles :
405+ if handle != main_window_handle :
406+ self .driver .switch_to .window (handle )
407+ popup_opened = True
408+ break ;
409+
396410 selected_issue_ids = []
397-
398- tbody = wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , ".popup-table > tbody" )))
411+
412+ tbody = wait .until (EC .presence_of_element_located ((By .CSS_SELECTOR , ".popup-table > tbody" )))
399413 rows = tbody .find_elements (By .CSS_SELECTOR , "tr" )
400414 # select upto 5 odd rows
401415 max_select = 10 if len (rows ) > 10 else len (rows )
@@ -470,19 +484,26 @@ def tearDown(self):
470484 def test_Untitled1 (self ):
471485 wait = WebDriverWait (self .driver , 10 )
472486 actions = ActionChains (self .driver )
487+ # Store window handle
488+ main_window_handle = self .driver .current_window_handle
473489
474490 # Click on element with link text 'Create New'
475491 wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "Create New" ))).click ()
476492
477493 # Click on element with link text '(list)'
478494 wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "(list)" ))).click ()
479495
480- # Store window handle
481- main_window_handle = self .driver .current_window_handle
482496 # Switch to the popup window
483- self .driver .switch_to .window (self .driver .window_handles [- 1 ])
484-
497+ popup_opened = False
498+ while (not popup_opened ):
499+ for handle in self .driver .window_handles :
500+ if handle != main_window_handle :
501+ self .driver .switch_to .window (handle )
502+ popup_opened = True
503+ break ;
504+
485505 selected_issue_ids = []
506+ wait .until (EC .presence_of_element_located ((By .ID , "popup-search" )))
486507
487508 # search the pytest issue with title and status
488509 self .driver .find_element (By .NAME , "keyword" ).send_keys ("test" )
0 commit comments