JupyterLab notebooks - accessing a specific code cell, reading/writing/replacing code in it

Hi Cristina,

I didn’t have edge on my mac, so I used Chrome, but otherwise this example below should work for you.

Dave.

cristina_JupyterLite.robot

*** Settings ***
Documentation 	This is the starter code to open a jupyterlab notebook
Library 	SeleniumLibrary
Library 	Screenshot

*** Variables ***
# ${URL}= 	JupyterLite
${URL}= 	https://jupyter.org/try-jupyter/lab/
${NOTEBOOK_FOLDER}= 	//*[@id="filebrowser"]/div[4]/ul/li[2]/span[2]
${NOTEBOOK}= 	//*[@id="filebrowser"]/div[4]/ul/li[2]/span[2]
${codeblock3}= 	(//div[contains(@class, "jp-CodeCell")])[3]//div[@class="CodeMirror-code"]

*** Test Cases ***
Logging in
	# Open Browser 	${URL} 	edge
	Open Browser 	${URL} 	chrome
	Set Selenium Timeout	60s
	Set Window Size 	1600 	1000
	Wait Until Page Contains 	notebooks

Navigation to ‘notebook’ folder
	Double Click Element 	${NOTEBOOK_FOLDER}
	Wait Until Page Contains 	Lorenz

Open notebook
	Double Click Element 	${NOTEBOOK}
	Wait Until Page Contains Element 	${codeblock3}/pre
	# Take Screenshot

Edit Third Cell
	${count}= 	Get Element Count 	${codeblock3}/pre
	Log To Console 	count: ${count}
	Scroll Element Into View 	${codeblock3}/pre[${count}]
	Click Element 	${codeblock3}/pre[${count}]
	Press Keys 	None 	RETURN
	Press Keys 	None 	TAB
	Press Keys 	None 	print "example for cristina"
% robot cristina_JupyterLite.robot
==============================================================================
cristina JupyterLite :: This is the starter code to open a jupyterlab notebook
==============================================================================
Logging in                                                            | PASS |
------------------------------------------------------------------------------
Navigation to ‘notebook’ folder                                       | PASS |
------------------------------------------------------------------------------
Open notebook                                                         | PASS |
------------------------------------------------------------------------------
Edit Third Cell                                                       .count: 41
Edit Third Cell                                                       | PASS |
------------------------------------------------------------------------------
cristina JupyterLite :: This is the starter code to open a jupyter... | PASS |
4 tests, 4 passed, 0 failed
==============================================================================

2 Likes