您不需要在
executescript这里使用:
require(RSelenium)checkForServer()startServer()remDr<-remoteDriver()remDr$open()remDr$getStatus()remDr$navigate("http://fyed.elections.on.ca/fyed/en/form_page_en.jsp")p.pres<-c('m1p4v4', 'n3t2y3', 'n2h3v1')webElem<-remDr$findElement(using = 'id', value = "ppre")webElem$sendKeysToElement(list(p.pres[1])) # send the first post pre to the elementremDr$findElement("id", "en_btn_arrow")$clickElement() # find the submit button and click it如果您想使用它,
executescript则可以将最后一行替换为:
remDr$executescript("arguments[0].click();" , list(remDr$findElement("id", "en_btn_arrow")))executescript将脚本作为参数和列表。如果列表中的任何元素属于类,
webElement则可以像DOM元素一样在脚本中引用它们。在这种情况下,第一个元素(Javascript中的零索引)是a
webElement,我们要求在Javascript中单击它。
此外,如果您检查按钮后面的源代码,就会发现在按下按钮时它会
document.ppre.submit()更简单地调用(在这种情况下,如果您想使用),
executescript您可以执行以下操作:
remDr$executescript("document.ppre.submit();")


