Selenium For Beginners

Share this post

User's avatar
Selenium For Beginners
How to check that the save popup is not displayed after clicking the save button?
Waits

How to check that the save popup is not displayed after clicking the save button?

Alex Siminiuc's avatar
Alex Siminiuc
Nov 10, 2024
∙ Paid
1

Share this post

User's avatar
Selenium For Beginners
How to check that the save popup is not displayed after clicking the save button?
Share

So you have a popup focused on creating a new user.

Your Selenium test fills in the new user details and then clicks the SAVE button.

Clicking the SAVE button closes the popup.

Before continuing to interact with the page, you check first that the popup is closed.

Your code may look like this:

WebElement saveButton = driver.findElement(SAVE_BUTTON_ID); 
saveButton.click(); 

boolean isPopupDisplayed = true;

try { 
   isPopupDisplayed = driver.findElement(POPUP_TITLE_ID).isDisplayed(); 
} 
catch (Exception e) { 
   isPopupDisplayed = false;		
} 

if (isPopupDisplayed) 
   throw new PopupNotHiddenException("the popup is still displayed!"); 

The code finds the save button and clicks it.

Then, it finds the popup title.

If the popup title can be found, isPopupDisplayed gets the true or false value. If the popup title cannot be found, an exception is generated and caught so that isPopupDisplayed becomes false.

If isPopupDisplayed is still true, an exception is generated since the popup is still visible.


There are multiple problems with this code:

  1. it uses try/catch statement

  2. it uses if statement

  3. it does not work at all if the popup is closed slowly

Keep reading with a 7-day free trial

Subscribe to Selenium For Beginners to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Alex Siminiuc
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share