How to run javascript using RSelenium?
Asked Answered
S

2

2

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:

enter image description here

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

Scullery answered 5/3, 2018 at 5:2 Comment(0)
D
2

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"))
Dillie answered 5/3, 2018 at 5:16 Comment(0)
O
1
element = remDr$findElement(using='xpath','//*
[@id="filters_detail_language_filterLang_ALL"]')
script <-"document.getElementById('filters_detail_language_filterLang_ALL').click();"
remDr$executeScript(script, args=list(element))
Omari answered 14/10, 2020 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.