简体   繁体   English

R - 在捕获 Rselenium 表达式时抑制 try() 输出到控制台

[英]R - Suppress try() output to console when trapping an Rselenium expression

The following code sends output to the console when the expression fails even though the try() argument silent = TRUE .即使try()参数silent = TRUE表达式失败,以下代码也会将输出发送到控制台。

dd = try(unlist(remDr$findElement("css", "#ctl00_mainA")), silent = TRUE)

suppressMessages() does not suppress the output. suppressMessages()不会抑制输出。

dd = suppressMessages(try(unlist(remDr$findElement("css", "#ctl00_mainA")), silent = TRUE))

try() is used to trap the error Selenium message: Unable to locate element: ........ . try() 用于捕获错误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().由 print() 和 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().我想抑制消息,同时保留使用 print() 和 cat() 向控制台发送消息的能力。

Would appreciate any ideas.将不胜感激任何想法。

Use remDr$findElements() instead with the same arguments.使用remDr$findElements()代替相同的参数。 If the element you are looking for doesn't exist it just returns a zero length list which is easy to test for, and you don't get a lengthy error message printed to the console.如果您要查找的元素不存在,它只会返回一个易于测试的零长度list ,并且您不会在控制台上看到冗长的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM