1

I am working with a form that does not allow to type accents, but it does allow to paste text with accent.

How can I send text to the clipboard, then paste the text containing accent into the form?

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
options = Options()
options.headless = True
driver = webdriver.Chrome('chromedriver.exe',options=options)

driver.get('https://www.website.com')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, openform))).click()

send accent text to clipboard


driver.find_element(By.XPATH, formfield).send_keys(Keys.CONTROL, 'v')
Dandal
  • 166
  • 1
  • 11
  • So you want to send_keys, highlight ctrl a, copy ctrl c and then paste ctrl v? – Arundeep Chohan Oct 04 '20 at 01:08
  • I want to insert the text to paste with selenium directly to the clipboard – Dandal Oct 04 '20 at 01:36
  • Why don't u just send the text that u wanna enter to the textbox via ```send_keys```? – Sushil Oct 04 '20 at 03:16
  • because the text box does not allow accents, but it does allow accented text when pasting it – Dandal Oct 04 '20 at 03:20
  • You've got an answer below - but have you tried setting your text via javascript? - using the clipboard is potentially over complicating your soltuon. – RichEdwards Oct 04 '20 at 08:26
  • I have not dealt with javascript. When but the text or I write it, the text box transforms it into capital letters with or without accent. – Dandal Oct 04 '20 at 12:15

1 Answers1

1

You could try this in python to copy the desired text in clipboard and then pasting it. It is working with python 3.8. You can try it too. if you face any issue then let me know.

import pyperclip
pyperclip.copy('Text to be copied to the clipboard.')
clipboard_text= pyperclip.paste()
print(clipboard_text)
UnknownBeast
  • 979
  • 1
  • 6
  • 13