close

How to send ESC key to close pop up window using Python and Selenium?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to send ESC key to close pop up window using Python and Selenium in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to send ESC key to close pop up window using Python and Selenium?

  1. How to send ESC key to close pop up window using Python and Selenium?

    I code my Selenium Python scripts in the AppRobotic Personal editor, and just insert its Windows macro functionality in between Selenium actions.

  2. send ESC key to close pop up window using Python and Selenium

    I code my Selenium Python scripts in the AppRobotic Personal editor, and just insert its Windows macro functionality in between Selenium actions.

Method 1

You don’t need to send keys to the element, you need to press them globally (to browser).

You can do it via Actions.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()

Method 2

I code my Selenium Python scripts in the AppRobotic Personal editor, and just insert its Windows macro functionality in between Selenium actions.

import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver

x.Type("{ESCAPE}")

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read