How to run javascript using RSelenium?

我的梦境 提交于 2020-07-22 21:35:40

问题


I am trying to click an input object on a webpage using a JS call. First, I'm using RSelenium to pull up the page:

library(RSelenium)

rD <- rsDriver(port = 4444L, verbose = FALSE)
remDr <- rD$client
remDr$navigate('https://www.tripadvisor.com/Hotel_Review-g293913-d306432-Reviews-Ambassador_Hotel_Taipei-Taipei.html')

From the page I'm trying to click on the button "All languages" from the menu below:

I was trying to trigger the click with a call to JS, which works when running the script in the chrome console

script <- "document.getElementById('filters_detail_language_filterLang_ALL').click();"
remDr$executeScript(script, args=list())

But I get the following error:

remDr$executeScript(script, args = list())

Selenium message:unknown error: 'args' must be a list (Session info: chrome=64.0.3282.186) (Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.12.4 x86_64)

Error: Summary: UnknownError Detail: An unknown server-side error occurred while processing the command. Further Details: run errorDetails method


回答1:


There may be a bug in RSelenium as such.

Try passing an dummy argument in the list method .

Use this:

remDr$executeScript(script, args = list("fugazi"))


来源:https://stackoverflow.com/questions/49103753/how-to-run-javascript-using-rselenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!