Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

Why can Selenium not handle alerts, pop-ups, and other web page elements?

In Selenium, an alert is a small message box on the user's screen to provide information or notification. It alerts the user with specific facts or errors, requests authorization to carry out particular tasks, and displays warning messages.

Let’s discuss a few methods on how you can handle alerts in Selenium -

  • void dismiss() - When a pop-up window appears, the dismiss() method clicks the "Cancel" button.
  • void accept() - The accept() method activates the pop-up window's "Ok" button as soon as it appears.
  • String getText() - The text displayed in the alert box is returned by the getText() function.
  • void sendKeys() - The sendKeys() function enters the given string pattern into the alert box.

Below are the following methods to handle pop-ups in Selenium -

  • Driver.getWindowHandles() - To switch between different open windows, use the Driver.getWindowHandles() function. It stores a set of handles for all currently open pages.
  • Driver.getWindowHandle() - Obtains the handle of the focussed web page. Driver.getWindowHandle() also acquires the address of the active browser.

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS


24/7 support


Enterprise grade security


Fastest test execution cloud