While I have a strong understanding of R, my knowledge in javaScript and other languages is very limited. My goal is to access information from a publicly-available data set found here: . Specifically, I have a list of postal codes formatted as 'A1A1A1' within a data frame. I want to input each of these postal codes into the website and then extract the name of the electoral district that is returned. RSelenium appears to be the ideal tool for this task, but I am struggling with getting the javascript to function properly.
require(RSelenium)
checkForServer()
startServer()
remDr<-remoteDriver()
remDr$open()
remDr$getStatus()
remDr$navigate("http://fyed.elections.on.ca/fyed/en/form_page_en.jsp")
#Upon inspecting the source code, it is clear that the input box has the id 'pcode', representing postal code
webElem<-remDr$findElement(using = 'id', value = "pcode")
webElem$getElementAttribute('id')
#This is where I am encountering difficulties
remDr$executeScript(script='arguments[0].click(m1p4v4)', list(webElem))
#Since I have numerous postal codes, I aim to create a loop to gather all district names from the successfully executed javascript (as seen in the previous command). Here are three real postal codes with results:
p.codes<-c('m1p4v4', 'n3t2y3', 'n2h3v1')
I believe my struggle lies in understanding the necessary javascript commands or the syntax of executeScript to achieve the desired outcome. Any assistance would be greatly appreciated.