[Python] Selenium python code to close this pop-up video?

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    This appears to be a Google Video ad - I am not sure how to close it in Selenium python. Note that I have to close it with its close button or a method that has the same effect to get it counted as properly closed.

    I am not even sure how to switch to it. I start with the URL to the original page in the background which has no relation to Google by the way. I would like to find a way to switch to it, then close it in Selenium python. If there is a code I can run to find the details of the floating video Ad you need to assist me with the actual closing code, please provide it and I will run it.

    I have tried using Developer tools while clicking the button that launches it, but is either buried in a JavaScript or multiple levels of DIVs in its own HTML page (separate from the background page where I clicked the button that launches the video).

    I also tried using the Selector (using JavaScript) and ID of the close button but I guess find_element By.ID. But neither works as I suspect I still have the driver (driver.get()) referencing the background page that held the video-launching button.

    It would be nice if I can detect when the video ends also. The length can be variable so for now I just use a time.sleep(30) which is sometimes too long or too short.

    Thank you! enter image description here

    Continue reading...

Compartilhe esta Página