简体   繁体   中英

How to handle multiple pop-ups with selenium firefox webdriver

I have a situation as shown on SS below.

多个弹出窗口问题

I am testing some web app with selenium (java) and in one moment I got 4 pop-ups at the same time. I want to dismiss them all, but actually I can't get 3 of them.

I was searching how to handle multiple pop ups, and found this topic: How to handle multiple alert popup confirmation in selenium? - but that is not what I'm searching for.

First time driver.switchTo().alert() is returning an alert and I can dismiss it. But second time, it is null and impossible to switch on remaining pop ups.

I also tried things from this topic ( https://sqa.stackexchange.com/questions/8416/how-to-switch-handle-close-particular-popup-window-when-multiple-popups-are-ope ) with driver.getWindowHandles(), but it returns only one handle, so there is no multiple windows to switch.

So, my problem is that I can't get remaining three pop ups and dismiss them, any hints or someone had same problems?

Thanks.

尝试获取该弹出窗口的文本,字符串str = driver.switchTo()。alert()。getText(),然后尝试从第一个弹出窗口切换到另一个弹出窗口

I had a similar problem and had to solve it using autoit instead of selenium. Try this (with page_title being the title of the popup window and assuming you are on a windows machine) :

from win32com.client import Dispatch
autoit = Dispatch("AutoItX3.Control")

def _window_movement_windows(page_title):
        autoit.WinSetOnTop(page_title, "", 1)
        autoit.WinActivate(page_title, "")
        autoit.WinWaitActive(page_title)

Here's how to install and use AutoIt : Calling AutoIt Functions in Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM