使用应用循环时出现rselenium驱动程序错误
我正在使用rselenium在Firefox中自动进行页面导航。My rscript为不同的条件导入一个数据帧,并创建一个自定义函数,然后使用apply命令调用该函数。在函数中,每一列都通过如下方式引用:使用应用循环时出现rselenium驱动程序错误,r,selenium,runtime-error,rselenium,R,Selenium,Runtime Error,Rselenium,我正在使用rselenium在Firefox中自动进行页面导航。My rscript为不同的条件导入一个数据帧,并创建一个自定义函数,然后使用apply命令调用该函数。在函数中,每一列都通过如下方式引用: #create the function example <- function(dat) { webElem$sendKeysToElement(list(dat[[column1]])) #Enters text from the column in the web
#create the function
example <- function(dat) {
webElem$sendKeysToElement(list(dat[[column1]]))
#Enters text from the column in the web driver
}
apply(df, 1, example) #Should repeat the function for each row of the data
nextBtn(pageBody, remDr)
我认为它可以追溯到函数开头的
findElements
调用或sendkeystelement
调用。我尝试过关闭、退出和重新初始化远程驱动程序,但似乎没有什么不同。有没有关于故障排除的提示?或者是在r中使用selenium进行重复导航的好方法?我能够通过将代码从apply
函数重新编译为for(…)
循环来解决这个问题。我所创建的函数变化最小
- 我在循环开始时启动了web驱动程序
这是以下的简写:remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE)) remDr$open(silent = TRUE) remDr$navigate(url)
nextBtn <- function(element=pageBody, driver=remDr) { Sys.sleep(.5) driver$findElement(using = 'id',value = "NextButton")$clickElement() Sys.sleep(2.5) }
for (i in 1:nrow(df)) {
surveys(df[i,])
}
最终的结果是循环运行。它每次都会打开一个新的驱动程序实例,但没有错误。对特定列的引用仍然使用df[[mold0to2]]
remDr$close()
remDr$quit()
for (i in 1:nrow(df)) {
surveys(df[i,])
}