leochabi / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 1 forks source link

Pressing keyboard keys (Esc, Enter) #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system : Win7
.Net Framework version : 2.0.7045
Office Version : 2003
SeleniumWrapper version : 1.0.11.0

Please could you provide sample VBA code, that will simulate physically 
pressing keyboard keys (ESc, Enter) and possibly also instruction how other 
keys can be pressed.

Original issue reported on code.google.com by steepd...@gmail.com on 6 May 2013 at 8:30

GoogleCodeExporter commented 8 years ago
There you go :

Dim selenium As New SeleniumWrapper.WebDriver
Dim Keys As New SeleniumWrapper.Keys
selenium.Start "firefox", "http://www.google.com"
selenium.Open "search?q=eiffel+tower"

selenium.SendKeys Chr(9) // ascii code for escape
Or
selenium.SendKeys Keys.Escape  // Send escape to the active element
Or
selenium.findElementById("id").SendKeys Keys.Enter  'Send enter to the element

Original comment by florentbr on 6 May 2013 at 12:53

GoogleCodeExporter commented 8 years ago
To close a windows popup, you first have to to use the switchToWindow command.
Then you can try to send the escape key :

selenium.switchToWindow "windows-name"
selenium.sendKeys Keys.Escape

For the "id=x-auto-32", you can use a CSS selector with partial id :
selenium.findElementByCssSelector("a[id^=x-auto-]").click

Original comment by florentbr on 10 Jul 2013 at 11:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago

Original comment by florentbr on 8 Sep 2014 at 5:40