@@ -49,15 +49,29 @@ def wait_for_idle_status(driver, current_cell, start_time, timeout):
4949
5050 print (current_cell .text )
5151
52+ def rewind_to_first_cell (cell ):
53+ while True :
54+ prev = cell .find_elements (
55+ By .XPATH ,
56+ "preceding-sibling::div[contains(@class,'jp-Notebook-cell')][1]"
57+ )
58+ if not prev :
59+ return cell
60+ cell = prev [0 ]
61+
62+
5263
5364def run_notebook (driver , notebook_area , args ):
5465 """This functions runs all the cells of the notebook"""
5566 print ("Running Cells" )
5667 start_time = time .time ()
68+ current_cell = driver .find_element (
69+ By .CSS_SELECTOR , ".jp-Notebook-cell.jp-mod-selected"
70+ )
71+
72+ current_cell = rewind_to_first_cell (current_cell )
73+
5774 while True :
58- current_cell = driver .find_element (
59- By .CSS_SELECTOR , ".jp-Notebook-cell.jp-mod-selected"
60- )
6175 editor_divs = current_cell .find_elements (
6276 By .CSS_SELECTOR , ".jp-InputArea-editor div"
6377 )
@@ -114,6 +128,11 @@ def run_notebook(driver, notebook_area, args):
114128 wait_for_idle_status (driver , current_cell , start_time , args .timeout )
115129
116130
131+ current_cell = current_cell .find_elements (
132+ By .XPATH ,
133+ "following-sibling::div[contains(@class,'jp-Notebook-cell')][1]"
134+ )
135+
117136def download_notebook (driver ):
118137 """This function is used to download the notebook currently open."""
119138 print ("Downloading notebook by clicking download button" )
0 commit comments