How do I "paste" in Selenium/VBA to browser textfield?
I downloaded and installed this: https://code.google.com/p/selenium-vba/
I managed to start Selenium in Firefox (CTRL-ALT-S) and recorded my steps for automation. I changed the code language to VBA in there and copied it to paste it in Excel.
For those of you who want to know what to do in Excel (2013):
Right click "Start"
Customize Ribbon
Check "Developer Tools" on the right
Click OK > Click on "Developer Tools" > Click "Visual Basic" > Click "Extras" > Click "References" > Look for "SeleniumWrapper Type Library" and check it > Click OK > In Menu bar click on the top arrow beside "Paste UserForm" > Click "Module" > Now paste the VBA Code from Selenium (Firefox) Plugin in there
Everything works perfectly fine but I want it to do repetitive web browser tasks so it should copy Excel cells and paste it in Textboxes in Websites for example in the Google Searchbar.
I already found a solution for the copying part:
Range("A1").Copy
It works but I can't find any working solution for the pasting part. Tested but didn't work:
driver.findElementById("ID").SendKeys "^v" gives out "v" instead of pasting.
driver.findElementById("ID").SendKeys(Keys.chord(Keys.CONTROL, "v")); Doesn't accept ";" and also doesn't work without.
I also tried several "Wait" and "Sleep" codes but neither do I know for sure which of them actually work nor if they are necessary.
driver.action.key_down(: control) Didn't work.
driver.findElementById("ID").keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0076')).perform(); Syntax error, without ";" "Error: List Delimiter" and marks the "." between "String" and "value".
I am grateful for any advice!
The easiest way is to send the text:
Dim driver As New FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
driver.FindElementById("searchInput").SendKeys [A1]
If you really need to use the clipboard:
Dim Keys As New Selenium.Keys
Dim driver As New Selenium.FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
driver.SetClipBoard [A1]
driver.FindElementById("searchInput").SendKeys Keys.Control, "v"
Of course it depends on the kind of element you want to paste the text to, but how about just setting the element's value directly;
driver.findElementById("ID").text = Range("A1").value2
Related
I need a way to disable the ability for a user to go to (or use) the menu File > Share
I have similar for other save commands like below but need something for this feature as well
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False
I have tried:
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Share").Enabled = False
to no avail
My aim is to stop users saving copies of this file (Hosted on a server), I fully understand Excel isn't meant to be secure and there is always a way to do this but want to make it as hard as I can for the average Joe
Regards
You could use a for each loop to extract the available commands:
' Iterate available commands from the file command bar.
Sub PrintAllCommandBarControlNames()
Dim cbControl As CommandBarControl
For Each cbControl In Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls
Debug.Print cbControl.Caption
Next
End Sub
Run on Excel 2010, I couldn't find a share option. Might just be my system. The above returned:
&New...
&Open...
&Close
&Save
Save &As...
Single Web Page (*.mht)
Save &Workspace...
File Searc&h...
Per&mission...
Per&mission
Ch&eck Out
Ch&eck In...
Ve&rsion History...
We&b Page Preview
Page Set&up...
Prin&t Area
Print Pre&view
&Print...
Sen&d To
Propert&ies
&Recent File Name Goes Here
&Recent File Name Goes Here
Sign ou&t
E&xit Excel
The 'backstage' menu (that you get when you click top left File menu) is effectively part of the Ribbon, and not a Command Bar. If you tried disabling Save for instance, using your example, you'll find they don't work on 2010/2013 etc.
There is this answer which tells you how to manipulate those menu items in the ribbon: Remove "Save & Send" from File menu in Excel 2010 using custom XML and one of the items is called TabShare.
I have been trying to do this myself, but I just dont know how to define the problem. I have been writing a Macro for LibreOffice and it includes several dialogs. When I Run the macro I want to execute a Function after the dialog is visiable. I could not find the solution to this so I made another dialog which only shows "Loading, Wait..." and I inserted at the beggining and end of that function, dialog.Execute() and dialog.endExecute(). I guess the program stops at .execute() and im stuck at "Loading, Wait..." sign if I press "X" in the corner the program continues normally.
Best solution would be if I could run a function after the dialog is visible. So is there sort of a trigger ?
You can load the dialog and make it visible, but this would not activate the functions (buttons etc.), as this is what execute does
' StarBasic
' Tools
With GlobalScope.BasicLibraries
If ( Not .isLibraryLoaded("Tools") ) Then
.LoadLibrary( "Tools" )
End If
End With
sampleDialog = LoadDialog( "Standard", "Dialog1")
sampleDialog.setVisible(TRUE)
Does this help you?
Does Excel VBA object model allows for access to keyboard shortcuts to VBA IDE menu items ?
(I would like to create additional item in menu and connect it with choosen shortcut)
For example code below returns "C&lear" which means you can access "Clear" item by typing "l" when the "Edit" group in VBE IDE is active, but you can also access "Clear" by typing "Delete" button alone :
Debug.Print Application.VBE.CommandBars(1).Controls(2).Controls(6).Caption
is there a way to find pragrammaticaly direct shortcut to item in IDE menu ("Delete" in the case above) ? I would like to add item to VBA IDE menu with new custom shortcut ?
Debug.Print Application.VBE.CommandBars(1).Controls(3).Controls(6).Caption
returns "&Immediate Window" but you could also access Immediate Window by direct shortcut "Ctrl+G"
is there a way to find pragrammaticaly direct shortcut to item in IDE menu ("Delete" in the case above)
Yes, there is. Try this
Debug.Print Application.VBE.CommandBars(1).Controls(2).Controls(6).ShortcutText
This will give you Del
Followup from comments:
Dim b As CommandBarButton
Set b = Application.VBE.CommandBars(1).Controls(2).Controls(6)
Debug.Print b.TooltipText
returns:
C&lear (Del)
Similarly,
Set b = Application.VBE.CommandBars(1).Controls(2).Controls(6)
Debug.Print b.TooltipText
returns
Export (Ctrl+E)
I am looking for a way to programatically open the "New Document" dialog in Word 2007. It is the same one you get when you select File->New . You can also open it using the FileNew macro or the "New..." menu command. However, I have been unable to find a way to do this programmatically.
I have tried:
Application.Run MacroName:="FileNew"
and
Dialogs(wdDialogFileNew).Show
and
CommandBars.FindControl(ID:=5746).Execute
but both of these open the old dialog, not the new one that word 2007 uses.
If a 'real' VBA command exists for open that dialog, I can't find it. However, I did find this utterly lame workaround via some quick googling:
SendKeys "%"
SendKeys "F"
SendKeys "N"
It does what you want though! Found it here http://www.eggheadcafe.com/software/aspnet/32228837/new-file-dialog-in-word-2.aspx
You could get the Command ID for the button and execute it?
Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute
Control ID 18 is the word application ID for the New... button.
I think that you can just use:
Documents.Add
without any parameters.
I always run into this situation: cursor is on line 5 and I want to select everything down to line 16. I have to resort to shift-arrow, arrow, arrow, or use the mouse.
NetBeans has "go to line" (Control-G) but you can't hold down shift while doing that, so no good for selecting. There's also "bookmarks," but same problem.
Anyone know of a cool trick that solves this problem?
I'm open to alternate tool suggestions for OS X.
You can use Shift-PgDn or Shift-PgUp to select the next "page" of information.
The only thing that comes to mind is to create an editor macro.
Eg:
Tools > Options > Editor > Macros
Click "New" Enter a name:
Enter a name for the macro: select-5-down
For the macro code enter:
selection-down
selection-down
selection-down
selection-down
selection-down
Click "Set Shortcut" and assign a key binding. I used Alt-M.
Now each click of Alt-M extends the selection by 5 more lines.