The following code sends output to the console when the expression fails even though the try() argument silent = TRUE.
dd = try(unlist(remDr$findElement("css", "#ctl00_mainA")), silent = TRUE)
suppressMessages() does not suppress the output.
dd = suppressMessages(try(unlist(remDr$findElement("css", "#ctl00_mainA")), silent = TRUE))
try() is used to trap the error Selenium message: Unable to locate element: ......... The code logic works perfectly; the script continues to run as intended.
The message is not an Error that appears in red. The message is in black; the same color that results from print() and cat().
Echo is off. The source code does not print to the console.
I want to suppress the message while retaining the ability to send messages to the console with print() and cat().
Would appreciate any ideas.
Use
remDr$findElements()instead with the same arguments. If the element you are looking for doesn't exist it just returns a zero lengthlistwhich is easy to test for, and you don't get a lengthy error message printed to the console.