简体   繁体   中英

How to handle pop-up in Chrome Selenium webdriver - Python

I was using a script to extract some data from the italian morningstar website and it was working fine. Although since few months, it is appearing a pop-up (caches) straight when I open the webpage.

I used to handle the pop-up by referencing the html element and close it. This method was working fine for a while, then I don't know why since few weeks ago every time I close the popup by accepting all the cookies and I browse into the webpage it continues to reappear (Even if I try to close the pop-up manually.).

If I navigate through Chrome, once I accept the cookies it stops showing, but with selenium webdriver if I accept the cookies the popup continues to show in the same internet session. I tried everything, including importing all the cookies from Chrome but nothing changed.

Do you have a suggestion?

Here is the pop-up showing

You can switch to pop up and close it if its a html popup. If its not, you must use some autoit/automac or something similar depending on the platform.

You coud try something like

     public static void PopUp()
    {
        _webDriver.SwitchTo().Alert().Accept();
    }

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