0

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!

2 Answers 2

1

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"
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.