'Recognizing and Clicking Alert with RSelenium

I'm having some difficulty with an alert I receive during a for loop. Effectively, I can't figure out how to recognize the alert when it comes up and then close it. So far, I've tried this:

if (is.character(mybrowser$getAlertText()) == TRUE) {
    mybrowser$acceptAlert
    }

I got it to recognize the alert text once, but when I try to use that in the if statement above it doesn't work. For reference, this is what the alert looks like (I'm using Windows 10, I know, I know).

UPDATE: I tried using a try function and it still won't close the alert but hangs instead. When I stop the program and attempt to close the alert in the console with mybrowser$acceptAlert(), it won't recognize the alert and hangs as well. mybrowser$switchToWindow(window) hangs as well. The page appears to be loading while the alert appears. I don't know if that matters.



Solution 1:[1]

I noticed you mentioned you've tried try function but alert still be there sometimes. You can try try(mybrowser$acceptAlert(), silent = TRUE) to handle error message instead of detecting your browser receiving an alert or not.

If alert happened, acceptAlert() function would be equivalent to clicking the OK button. If not, try() function would store error messages and handle it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vik Huang