Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用应用循环时出现rselenium驱动程序错误_R_Selenium_Runtime Error_Rselenium - Fatal编程技术网

使用应用循环时出现rselenium驱动程序错误

使用应用循环时出现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

我正在使用rselenium在Firefox中自动进行页面导航。My rscript为不同的条件导入一个数据帧,并创建一个自定义函数,然后使用apply命令调用该函数。在函数中,每一列都通过如下方式引用:

#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,])
}