Feb-17-2018, 09:32 AM
(This post was last modified: Feb-17-2018, 09:32 AM by digitalmatic7.)
Hey guys, I'm working on a small script that will check if there's more than 1 window (detect if there's a popup), and if it finds one it will switch to and close it down.
Here's what I have so far:
The thing is the popups are happening inside the original window (on page popups), and so the script does nothing lol.
The script ideally needs to close a wide range of popups (I can't easily target by class, or ID because the script encounters many different popups).. it's most important to block the lightbox style squeeze page popups.
At this point I'm thinking of just writing 50 if statements that search for the most common close popup elements.
What you guys think?
Here's what I have so far:
1 2 3 4 5 6 7 8 9 |
from selenium.common.exceptions import NoSuchWindowException if len (driver.window_handles) > 1 : try : driver.switch_to.window([ 2 ]) driver.close() driver.switch_to_default_content() except NoSuchWindowException: pass |
The script ideally needs to close a wide range of popups (I can't easily target by class, or ID because the script encounters many different popups).. it's most important to block the lightbox style squeeze page popups.
At this point I'm thinking of just writing 50 if statements that search for the most common close popup elements.
What you guys think?