3

I need in python to paste text that i have in the buffer(ctrl+v) to a web site that I open right into the text box open website with:

    driver = webdriver.Firefox()
    driver.get("https//..")
    item = driver.find_element_by_name('text')
    item.send_keys(Keys.CONTROL + "v")

i have python 2.7.13

when opening web from cmd:

Traceback (most recent call last):      #driver.get("https://bitbucket.wdc.com/plugins/servlet/ssh/account/keys/add")
      File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
        self.service.start()
      File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
        os.path.basename(self.path), self.start_error_message)
    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
furas
  • 134,197
  • 12
  • 106
  • 148
Eva Zana
  • 95
  • 8
  • "python 2.13" doesn't seem to exist. [Python 2.7.13 does, though](https://www.python.org/downloads/release/python-2713/). Also, what have you written in order to solve this? Where exactly are you facing issues? – ForceBru Feb 11 '20 at 20:09
  • [How to press Ctrl+V in Selenium WebDriver](https://stackoverflow.com/questions/18322883/how-to-press-ctrlv-in-selenium-webdriver) – furas Feb 11 '20 at 20:13
  • your problem has nothing to do with clipboard - it can't find `geckodriver.exe` which you need to get access to Firefox - see https://github.com/mozilla/geckodriver/ – furas Feb 11 '20 at 21:50
  • [Setting path to firefox binary on windows with selenium webdriver](https://stackoverflow.com/questions/25713824/setting-path-to-firefox-binary-on-windows-with-selenium-webdriver) – furas Feb 11 '20 at 21:54

1 Answers1

1

Selenium can send Ctrl+V and it will paste text from clipboard

import selenium.webdriver
from selenium.webdriver.common.keys import Keys 

driver = selenium.webdriver.Firefox()
driver.get('https://google.com')

item = driver.find_element_by_name('q')
item.send_keys(Keys.CONTROL + "v")

EDIT: I found some page with <textarea> and it works for me with <textarea> too.

Because <textarea> is inside <iframe> so I have to switch frame.

import selenium.webdriver
from selenium.webdriver.common.keys import Keys 

driver = selenium.webdriver.Firefox()
driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea')

frame = driver.find_element_by_id('iframeResult')
driver.switch_to.frame(frame)

item = driver.find_element_by_id('w3mission')
item.send_keys(Keys.CONTROL + "v")

You can also try to use paperclip to get text from clipboard and put it as normal text

import pyperclip

#pyperclip.copy('The text to be copied to the clipboard.')

text = pyperclip.paste()
#print(text)

import selenium.webdriver
from selenium.webdriver.common.keys import Keys 

driver = selenium.webdriver.Firefox()
driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea')

frame = driver.find_element_by_id('iframeResult')
driver.switch_to.frame(frame)

item = driver.find_element_by_id('w3mission')
item.clear()
item.send_keys(text)
furas
  • 134,197
  • 12
  • 106
  • 148
  • This is my html message box: I use item = driver.find_element_by_name('text') it dosent work :/ – Eva Zana Feb 11 '20 at 21:04
  • do you get any error message? Better show URL to this page in question. You can also try [paperclip](https://pypi.org/project/pyperclip/) to get text from clipboard to variable and put it in textarea as any other text from variable. – furas Feb 11 '20 at 21:33
  • I found some page with textarea and it works for me with textarea. – furas Feb 11 '20 at 21:35
  • I thinks the error is when opening the web – Eva Zana Feb 11 '20 at 21:40
  • if you have error then always put full error in question - it is always very important information. – furas Feb 11 '20 at 21:41