RSelenium And Javascript
I'm fairly proficient in R, but completely ignorant regarding javaScript and other languages. I would like to like to access information on this publicly-available data set (http:
Solution 1:
You dont need to use executeScript
here:
require(RSelenium)
checkForServer()
startServer()
remDr<-remoteDriver()
remDr$open()
remDr$getStatus()
remDr$navigate("http://fyed.elections.on.ca/fyed/en/form_page_en.jsp")
p.codes<-c('m1p4v4', 'n3t2y3', 'n2h3v1')
webElem<-remDr$findElement(using = 'id', value = "pcode")
webElem$sendKeysToElement(list(p.codes[1])) # send the first post code to the element
remDr$findElement("id", "en_btn_arrow")$clickElement() # find the submit button and click it
if you wanted to use executeScript
instead you would replace the last line with:
remDr$executeScript("arguments[0].click();"
, list(remDr$findElement("id", "en_btn_arrow")))
executeScript
takes a script as an argument and a list. If any elements of the list are of class
webElement
then they can be referred to in the script like a DOM element. In this case the first element (zero index in JavaScript) is a webElement
and we ask to click it in our JavaScript.
Furthermore if you examine the source code behind the button you will find when it is pressed it calls document.pcode.submit()
so more simply in this case if you wanted to use executeScript
you could do:
remDr$executeScript("document.pcode.submit();")
Post a Comment for "RSelenium And Javascript"