Search code examples
vbaselenium-webdriverpopup

How to inspect pop-up window when right click is not working? (Selenium VBA)


I need to click OK on a pop-up window, but right click is not working when the pop-up window is open (I can't inspect the element). If I leave Inspect window open, there is nothing happening. Please see the screenshots.

Popup screenshot

Webpage code

I haven't tried much as I don't know what element it is. I guess this website is using Java, I'm not familiar with it.


Solution

  • That dialog is not HTML, it's a JavaScript alert. You need to switch to the Alert and then Accept it.

    Code sample

    Sub Test()
        Dim popup As Selenium.Alert
        Set driver = New Selenium.ChromeDriver
        With driver
            .Get "http://the-internet.herokuapp.com/javascript_alerts"
            .FindElementByCss("button[onclick='jsConfirm()']").Click
            Set popup = .SwitchToAlert(Raise:=False)
            popup.Accept
        End With
    End Sub