Selenium Modal showing up twice or more

Viewed 38

I am not good whatsoever with selenium nor c# however here is the issue I am running into, I have a modal contained in zipModal my issues is I want a for loop to click on the modal until is no longer visible, I have tried a lot of different options and can't seem to figure it out.

                if (basePage.IsElementPresent(zipModal))
                {                    
                    foreach (var modal in zipModal)
                    {
                        Thread.Sleep(2000);
                        if (!basePage.IsElementPresentXPath(cityModal))
                        {
                            basePage.Click("[class*='row zip-row highlighted']");
                        }
                        else
                        {
                            basePage.Click("[class*='row zip-caption']");
                            basePage.ClickCity(cityModal);
                        }
                    }
                    
                }
1 Answers

We can't see the page you are working on, but it can be that even after closing the dialog the element is still presented on the page, so you possibly should use here IsElementVisible instead of IsElementPresent.
Also, I don't understand your foreach (var modal in zipModal) line.
In case it is a single modal that may appear several times and could be clicked several times before it is finally closed and no more appears again your code could be something like the following:

while(basePage.IsElementVisible(zipModal)){
     basePage.Click(click the element closing the modal);
     Thread.Sleep(1000); 
}
Related