13
13
pjoin = os .path .join
14
14
15
15
16
- def wait_for_selector (driver , selector , timeout = 10 , visible = False , single = False , wait_for_n = 1 ):
16
+ def wait_for_selector (driver , selector , timeout = 10 , visible = False , single = False , wait_for_n = 1 , obscures = False ):
17
17
if wait_for_n > 1 :
18
18
return _wait_for_multiple (
19
19
driver , By .CSS_SELECTOR , selector , timeout , wait_for_n , visible )
20
- return _wait_for (driver , By .CSS_SELECTOR , selector , timeout , visible , single )
20
+ return _wait_for (driver , By .CSS_SELECTOR , selector , timeout , visible , single , obscures )
21
21
22
22
23
- def wait_for_tag (driver , tag , timeout = 10 , visible = False , single = False , wait_for_n = 1 ):
23
+ def wait_for_tag (driver , tag , timeout = 10 , visible = False , single = False , wait_for_n = 1 , obscures = False ):
24
24
if wait_for_n > 1 :
25
25
return _wait_for_multiple (
26
26
driver , By .TAG_NAME , tag , timeout , wait_for_n , visible )
27
- return _wait_for (driver , By .TAG_NAME , tag , timeout , visible , single )
27
+ return _wait_for (driver , By .TAG_NAME , tag , timeout , visible , single , obscures )
28
28
29
29
30
- def _wait_for (driver , locator_type , locator , timeout = 10 , visible = False , single = False ):
30
+ def wait_for_xpath (driver , xpath , timeout = 10 , visible = False , single = False , wait_for_n = 1 , obscures = False ):
31
+ if wait_for_n > 1 :
32
+ return _wait_for_multiple (
33
+ driver , By .XPATH , xpath , timeout , wait_for_n , visible )
34
+ return _wait_for (driver , By .XPATH , xpath , timeout , visible , single , obscures )
35
+
36
+
37
+ def _wait_for (driver , locator_type , locator , timeout = 10 , visible = False , single = False , obscures = False ):
31
38
"""Waits `timeout` seconds for the specified condition to be met. Condition is
32
39
met if any matching element is found. Returns located element(s) when found.
33
40
@@ -39,9 +46,12 @@ def _wait_for(driver, locator_type, locator, timeout=10, visible=False, single=F
39
46
visible: if True, require that element is not only present, but visible
40
47
single: if True, return a single element, otherwise return a list of matching
41
48
elements
49
+ osbscures: if True, waits until the element becomes invisible
42
50
"""
43
51
wait = WebDriverWait (driver , timeout )
44
- if single :
52
+ if obscures :
53
+ conditional = EC .invisibility_of_element_located
54
+ elif single :
45
55
if visible :
46
56
conditional = EC .visibility_of_element_located
47
57
else :
@@ -195,13 +205,19 @@ def wait_for_stale_cell(self, cell):
195
205
wait = WebDriverWait (self .browser , 10 )
196
206
element = wait .until (EC .staleness_of (cell ))
197
207
208
+ def wait_for_element_availability (self , element ):
209
+ _wait_for (self .browser , By .CLASS_NAME , element , visible = True )
210
+
198
211
def get_cells_contents (self ):
199
212
JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})'
200
213
return self .browser .execute_script (JS )
201
214
202
215
def get_cell_contents (self , index = 0 , selector = 'div .CodeMirror-code' ):
203
216
return self .cells [index ].find_element_by_css_selector (selector ).text
204
217
218
+ def get_cell_output (self , index = 0 , output = 'output_subarea' ):
219
+ return self .cells [index ].find_elements_by_class_name (output )
220
+
205
221
def set_cell_metadata (self , index , key , value ):
206
222
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}' .format (index , key , value )
207
223
return self .browser .execute_script (JS )
@@ -282,6 +298,9 @@ def run_all(self):
282
298
283
299
def trigger_keydown (self , keys ):
284
300
trigger_keystrokes (self .body , keys )
301
+
302
+ def is_kernel_running (self ):
303
+ return self .browser .execute_script ("return Jupyter.notebook.kernel.is_connected()" )
285
304
286
305
@classmethod
287
306
def new_notebook (cls , browser , kernel_name = 'kernel-python3' ):
0 commit comments