简体   繁体   中英

Send text to clipboard in selenium

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')

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM