Given the fact that I’m not a JS developer, and that I do want to get data in and out of my pod,
I decided to figure out how I could connect to my solid pod (in this case my inrupt one) to Rstudio.
This is my “hello world” version, to demonstrate that I can read and write on my datapod using R
Of course, it would be a lot better if I would do the login as an app that requests access.
The main goal is to be able to easily import and export big .ttl files for data science purposes.
Hope it’s usefull.
title: “solid Rselenium login”
author: “Christophe Cop”
date: “26-1-2021”
output: html_document
how to log in on your SOLID datapod using R
a lot of thanks to this tutorial!
R Markdown
Libraries
library(RSelenium)
library(tidyverse)
library(netstat)
setup and open a driver
driver <- rsDriver(browser=c("chrome"),port=free_port()) # seems to take some time.
remote_driver <- driver[["client"]]
remote_driver$open()
you should be able to see a rather empty chrome window popping up.
go to your web page
remote_driver$navigate("https://psycop.inrupt.net/profile/card#me")
this redirects to a login…
find the login button
I had to use xpath as a general find function, which I will continue using.
there may be other options that are more elegant though
button_element <- remote_driver$findElement(using = 'xpath', value = "/html/body/header/div/div/div/div/input[1]")
# the full xpath can be found in the "inspect" (on the browser ), right click, copy, full xpath
button_element$clickElement()
Select your Identity Provider pops up.
#now here is where the manual part comes in :
I failed to figure out how to go to the pop up window
remote_driver$getCurrentUrl()
so go to the pop-up manually and log in , takes a few steps
(might be safer in the end)
now, you are logged in, and you can see your logged in page
click the ‘</>’ button to get the .ttl format
button_element2 <- remote_driver$findElement(using = 'xpath', value = "/html/body/div/table/tr/td/table/tr[1]/td/div/nav/img[4]")
button_element2$clickElement()
click the “pencil” button to be able to edit the page
button_element3 <- remote_driver$findElement(using = 'xpath', value = "/html/body/div/table/tr/td/table/tr[2]/td/div/table/tr[3]/button[3]/img")
button_element3$clickElement()
read the content
webElem_text <- remote_driver$findElement(using = 'xpath', value = "/html/body/div/table/tr/td/table/tr[2]/td/div/table/tr[1]/textarea")
the_text <- webElem_text$getElementAttribute("value")
the_text[[1]][1]
to empty the content, use # element.clear() but be carefull… it’s gone!
write hello world
webElem_text$sendKeysToElement(list("\n# HELLO WORLD"))
once an eddit happened, a “save” button appears
save button
button_element4 <- remote_driver$findElement(using = 'xpath', value = "/html/body/div/table/tr/td/table/tr[2]/td/div/table/tr[3]/button[2]/img")
button_element4$clickElement()
go the person icon to see the lay-out again (the hello world is not vissible in it.)
button_element5 <- remote_driver$findElement(using = 'xpath', value = "/html/body/div/table/tr/td/table/tr[1]/td/div/nav/img[1]")
button_element5$clickElement()
close the session
remote_driver$close()