how to press Esc(Escape) key in selenium using webdriver.

52,485 views
Skip to first unread message

kamal

unread,
Feb 9, 2012, 12:43:21 PM2/9/12
to Selenium Users, kannan....@gmail.com
Hi all,

Can anyone tell me how to press Esc key in selenium using webdriver.

I have used selenium.Keypressnative("27"), it works fine in selenium 1
but not in webdriver. i am using Webdriverbackedselenium in my code.
But still it is not working.

It would be very needful if i get reply..


Thanks in advance,
Kamal...

Luke Inman-Semerau

unread,
Feb 9, 2012, 12:49:57 PM2/9/12
to seleniu...@googlegroups.com, kannan....@gmail.com
element.sendKeys(Keys.ESCAPE)

Kamal...

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Monika

unread,
May 12, 2012, 3:50:46 AM5/12/12
to seleniu...@googlegroups.com, kannan....@gmail.com
May be you are right Luke Inmam.....

But In My case i am getting an "org.openqa.selenium.UnhandledAlertException: Modal dialog present
This box is containing an "Ok" button . I have to click on this "ok" button to get back to my parent window.
This pop up goes away only by clicking "ok" button or by pressing "enter" or "Escape" key from keyboard.
When I try to Right Click on this "ok" no options are displayed to get its Xpath, CSS, Id etc. So there is not way to get the location of "Ok" button.

this pop can be gone by clciking "Enter" key or "ESC" from keyboard.

So In element.sendKeys(Keys.ESCAPE)
there is not way to get the Location of Webelement.

Can it done by just clicking the "Esc" key from keyboard


On Thursday, 9 February 2012 23:19:57 UTC+5:30, Luke Inman-Semerau wrote:
element.sendKeys(Keys.ESCAPE)

On Thu, Feb 9, 2012 at 9:43 AM, kamal <rajvi...@gmail.com> wrote:
Hi all,

Can anyone tell me how to press Esc key in selenium using webdriver.

I have used selenium.Keypressnative("27"), it works fine in selenium 1
but not in webdriver. i am using Webdriverbackedselenium in my code.
But still it is not working.

It would be very needful if i get reply..


Thanks in advance,
Kamal...

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Luke Inman-Semerau

unread,
May 13, 2012, 2:08:14 PM5/13/12
to seleniu...@googlegroups.com, kannan....@gmail.com
That's an alert or confirm dialog box. To handle that you do this:

Alert a = driver.switchTo().alert();
a.confirm(); // or dismiss() if you want to hit 'cancel'

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/Ec95H3yq34oJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
Message has been deleted

Sudhansu Sekhar panda

unread,
Apr 24, 2013, 2:42:59 AM4/24/13
to seleniu...@googlegroups.com, kannan....@gmail.com
Hi Kamal,

Please try with the below code.

           Actions action = new Actions(driver);
   action.sendKeys(Keys.ESCAPE);

Thanks,
Sudhansu

Mani

unread,
Mar 11, 2014, 9:08:55 AM3/11/14
to seleniu...@googlegroups.com, kannan....@gmail.com
Hi Kamal,
 
Facing the same problem. Iam using WebDriver. Can u pls tell how your problem got resolved?
 
 Actions action = new Actions(driver);
   action.sendKeys(Keys.ESCAPE);
the above code is also not working on this.
 
Thanks,
Mani.

Susovan Dutta

unread,
Mar 11, 2014, 2:45:18 PM3/11/14
to seleniu...@googlegroups.com, kannan....@gmail.com
Actions action = new Actions(driver);
   action.sendKeys(Keys.ESCAPE).build.perform;

Shadaab

unread,
Mar 12, 2014, 12:44:08 AM3/12/14
to seleniu...@googlegroups.com
If you are using Java you can go with Robot Library.

Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);

Rgds
Shadaab


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Ripon Al Wasim

unread,
Mar 12, 2014, 2:51:14 AM3/12/14
to seleniu...@googlegroups.com
Actions action = new Actions(driver);
action.sendKeys(Keys.ESCAPE).build().perform();


DongXiang

unread,
Mar 13, 2014, 5:34:46 AM3/13/14
to seleniu...@googlegroups.com
you can use robot to perform clicking "ESC" button. It will actually click "ESC" like manually do it.


Date: Tue, 11 Mar 2014 06:08:55 -0700
From: vinnu.st...@gmail.com
To: seleniu...@googlegroups.com
CC: kannan....@gmail.com
Subject: [selenium-users] Re: how to press Esc(Escape) key in selenium using webdriver.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Rejeesh Gopalakrishnan

unread,
Apr 23, 2014, 12:06:39 PM4/23/14
to seleniu...@googlegroups.com, kannan....@gmail.com
It worked exactly.
 
Thanks,
Rejeesh.
element.sendKeys(Keys.ESCAPE)

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

Denis Platonov

unread,
Apr 9, 2016, 12:41:16 AM4/9/16
to Selenium Users
It won't work if you're using RemoteDriver (i.e. Sauce labs or Selenium Grid)

Sarla Kumari

unread,
May 22, 2017, 8:06:33 AM5/22/17
to Selenium Users
It worked for me. Thanks

G S

unread,
Jul 11, 2018, 12:03:28 AM7/11/18
to Selenium Users
Thanks Susovan, that worked for me. :-)

sandhya rani palai

unread,
Dec 9, 2018, 11:37:25 AM12/9/18
to Selenium Users
Hi Shadaab,

This is not working for me. Could you please help.

Regards,
Sandhya

Md SaddaM Hossain

unread,
Dec 9, 2018, 12:27:28 PM12/9/18
to seleniu...@googlegroups.com
Try to use.. 
driver.findElement(By.tagName("body")).sendKeys(Keys.Escape);

MD S Hossain
Mobile: 7030400093

Reply all
Reply to author
Forward
0 new messages