1

I try to execute a javascript line which runs in JS console which is this:

window.document.querySelectorAll('.atbk[href*="/url"]')

I try to use it with the following script:

startServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate(a_url)
re <-  remDr$executeScript('return window.document.querySelectorAll('.atbk[href*="/url"]');')

Error: unexpected symbol in "re <-  remDr$executeScript('return window.document.querySelectorAll('.atbk"

Is there any difference in character I should use?

1 Answer 1

2

Use backslashes to escape the effects of the nested quotes in the string:

x <- "return window.document.querySelectorAll('.atbk[href*=\"/url\"]');"

It may look non-standard in the console, but internally the string is saved without the backslashes. You can check with ?cat:

cat(x)
return window.document.querySelectorAll('.atbk[href*="/url"]');

In case you are still unsure, here's a second test. You can see that \" is saved as one character:

> y <- "\""
> y
[1] "\""
> nchar(y)
[1] 1
> cat(y)
"
Sign up to request clarification or add additional context in comments.

2 Comments

I tried with the executeScript using this x <- remDr$executeScript("return window.document.querySelectorAll('.atbk[href*=\"/url\"]');") and a new error exists Error in out[[wInd]] : recursive indexing failed at level 3
If you would like to ask a second question about using RSelenium and it's functionality please ask after researching and troubleshooting the specific error you are receiving.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.