leochabi / selenium-vba

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

how to simulate CTRL+S in a web page #29

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system : windows
.Net Framework version :
Office Version :2010
SeleniumWrapper version :latest version

What is your issue ?

In a webpage , i would like to simulate a CTRL+S
followed by Enter 
how can i do that.
Many thanks

Original issue reported on code.google.com by alam...@gmail.com on 9 Oct 2013 at 8:58

GoogleCodeExporter commented 8 years ago
Unfortunately sending a native key combination doesn't work with the Selenium 
.Net framework.
Refer to : https://code.google.com/p/selenium/issues/detail?id=4965

Anyway, I will implement the Actions class for the next release. It should work 
like this :
element = driver.findElementById("id)
driver.Actions.keyDown(Keys.Control, element).sendKeys("s", element).perform();

I will also add a native keyboard class to send keys to a window and a native 
mouse class to click anywhere.

Original comment by florentbr on 11 Oct 2013 at 2:13

GoogleCodeExporter commented 8 years ago
There's a way to simulate key inputs with the WScript.Shell library.
Here is an example :

Dim shell: Set WshShell = CreateObject("WScript.Shell")
Dim driver As New SeleniumWrapper.WebDriver

driver.Start "firefox", "http://www.google.com"
driver.setImplicitWait 5000
driver.Open "/"
shell.SendKeys "^s" 'Send Ctrl+s to Firefox which opens the "Save as" dialogue 
box

Original comment by florentbr on 11 Oct 2013 at 12:03

GoogleCodeExporter commented 8 years ago
hello and thanks for your answer.
Regarding your code , I have tried it but how do you reference the shell 
library.
I am getting an error , please see the attachement.
Thanks for your help.

Original comment by alam...@gmail.com on 12 Oct 2013 at 10:16

GoogleCodeExporter commented 8 years ago
here is the attachement

Original comment by alam...@gmail.com on 12 Oct 2013 at 10:17

Attachments:

GoogleCodeExporter commented 8 years ago
My mistake, the object variable is not the one used to call SendKeys.

The correct code:
Sub TestShell()
    Dim shell: Set shell = CreateObject("WScript.Shell")
    Dim driver As New SeleniumWrapper.WebDriver

    driver.Start "firefox", "http://www.google.com"
    driver.setImplicitWait 5000
    driver.Open "/"
    shell.SendKeys "^s" 'Send Ctrl+s to Firefox which opens the "Save as" dialogue box
End Sub

Original comment by florentbr on 12 Oct 2013 at 1:43

GoogleCodeExporter commented 8 years ago
Works fine , thank you :)
the idea behind the ctrl + s is to have the save the webpage (works fine with 
firefox) so a save as window is displayed , is there a way to simulate the 
enter so that it save the page , here the code trigger the save as window and 
nothing happened after.
Thanks

Original comment by alam...@gmail.com on 12 Oct 2013 at 2:48

GoogleCodeExporter commented 8 years ago
The documentation for the SendKeys command :
http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx

In your case I would do :
shell.SendKeys "^s"
shell.Sleep 1000
shell.SendKeys "{ENTER}"

Original comment by florentbr on 12 Oct 2013 at 3:00

GoogleCodeExporter commented 8 years ago
I tried it ineed before , but nothing happened with 
shell.SendKeys "{ENTER}"
regarding shell.sleep 1000 , i am not sure it is supported.
Thanks

Original comment by alam...@gmail.com on 12 Oct 2013 at 3:15

GoogleCodeExporter commented 8 years ago
You're right, it's not supported.
The correct code is:
shell.SendKeys "^s"
driver.Wait 1000
shell.SendKeys "pagename.htm{ENTER}"

Original comment by florentbr on 13 Oct 2013 at 6:25

GoogleCodeExporter commented 8 years ago
Thanks , it does work fine now :)

Original comment by alam...@gmail.com on 13 Oct 2013 at 9:57

GoogleCodeExporter commented 8 years ago

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