How to press ESCAPE key in JAVA

1,808 views
Skip to first unread message

Oliver

unread,
Nov 9, 2011, 7:17:35 AM11/9/11
to Selenium Users
I use selenium + testNG for my automation testing,

I want to press Escape key during executing script.

I have tried with command:

selenium.presskey("locator", "27);
selenium.presskey("locator", "\\27);
selenium.presskey("locator", "\27);

but no one works,

Please help me,

Thank

cassio kenji

unread,
Nov 9, 2011, 7:22:04 AM11/9/11
to seleniu...@googlegroups.com
Hi,

I think you need to release the key after press. But I cannot say if  "\27" is the correct key to press... sorry :)

2011/11/9 Oliver <loiv...@gmail.com>

--
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.


Subhabrata Banerjee

unread,
Nov 9, 2011, 7:23:23 AM11/9/11
to seleniu...@googlegroups.com
selenium.keyPress("locator", "\\27);   

Mark Collin

unread,
Nov 9, 2011, 9:06:38 AM11/9/11
to seleniu...@googlegroups.com

You could always use the Keys object if you aren’t sure what key code is required:

 

import org.openqa.selenium.Keys;

 

selenium.keyPress("id=foo", “\\” + Keys.ESCAPE.toString());


-- This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error please notify postm...@ardescosolutions.com

Mike

unread,
Nov 9, 2011, 1:36:27 PM11/9/11
to Selenium Users
In this case, you shouldn't need the "\\", should you? The
Keys.ESCAPE.toString() should produce a string with an ASCII 27 in it,
I would think, or does it simply produce a string with the number in
it?

Mike

Mark Collin

unread,
Nov 9, 2011, 3:17:33 PM11/9/11
to seleniu...@googlegroups.com
Not sure, I think you do with the Selenium 1 API but I don't use that any
more.

Mike

--

Oliver

unread,
Nov 20, 2011, 11:09:51 PM11/20/11
to Selenium Users
Dear Mark,

I have tried import your package and run your command, but selenium
doesn't recognize key? I don't know why

Please see in screen shot

http://www.uphinhnhanh.com/images/52Image_3.png

On Nov 10, 3:17 am, "Mark Collin" <m...@ardescosolutions.com> wrote:
> Not sure, I think you do with the Selenium 1 API but I don't use that any
> more.
>
> -----Original Message-----
> From: seleniu...@googlegroups.com
>
> [mailto:seleniu...@googlegroups.com] On Behalf Of Mike
> Sent: 09 November 2011 18:36
> To: Selenium Users

> Subject: [selenium-users] Re: How to press ESCAPEkeyin JAVA


>
> In this case, you shouldn't need the "\\", should you?  The
> Keys.ESCAPE.toString() should produce a string with an ASCII 27 in it, I
> would think, or does it simply produce a string with the number in it?
>
> Mike
>
> On Nov 9, 6:06 am, "Mark Collin" <m...@ardescosolutions.com> wrote:
> > You could always use the Keys object if you aren't sure whatkeycode
> > is
> > required:
>
> > import org.openqa.selenium.Keys;
>
> > selenium.keyPress("id=foo", "\\" + Keys.ESCAPE.toString());
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.

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


>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>

> If you have received this email in error please notify postmas...@ardescosolutions.com

saran kumar

unread,
Nov 21, 2011, 12:50:33 AM11/21/11
to seleniu...@googlegroups.com
Hey Guys,
 
i think we can something with this.
 
# Press the ESC key
self.selenium.key_up('css=html', '27')
 
for further details pls refer the site for reference:https://gist.github.com/1341169

Thanks
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Oliver

unread,
Nov 21, 2011, 10:11:14 PM11/21/11
to Selenium Users
Dear Saran,

Your code is on Python, I'm concerning on Java

saran kumar

unread,
Nov 22, 2011, 2:22:13 AM11/22/11
to seleniu...@googlegroups.com

Hi Oliver,

Can you please try it out with this snipet and let me know.......

Page

.driver().findElement(By.xpath("//textarea[@name='element']")).sendKeys(Keys.ESCAPE);
Thanks and Regards
Saran Kumar.T

On Tue, Nov 22, 2011 at 8:41 AM, Oliver <loiv...@gmail.com> wrote:
Dear Saran,

Your code is on Python, I'm concerning on Java

Oliver

unread,
Nov 28, 2011, 10:12:36 PM11/28/11
to Selenium Users
@saran: it not work too, seem this web application is weird so it
can't understand key sent

do you have other suggestions?

Oliver

unread,
Dec 18, 2011, 9:58:03 PM12/18/11
to Selenium Users
Please notice: I'm working on RC so that code with Webdriver doesn't
work

Hariprasad K S

unread,
Dec 20, 2011, 4:14:25 AM12/20/11
to seleniu...@googlegroups.com
If you are java user , u can use robot class, it's built in package for java.awt.*;

Thanks,
-Hariprasad

On Mon, Dec 19, 2011 at 8:28 AM, Oliver <loiv...@gmail.com> wrote:
Please notice: I'm working on RC so that code with Webdriver doesn't
work
--
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.




--
Thanks & Regards
 Hariprasad KS


Reply all
Reply to author
Forward
0 new messages