将文本发送到硒中的剪贴板

问题描述

我正在使用一种不允许键入重音符号的表格,但是它确实允许粘贴带有重音符号的文本。

如何将文本发送到剪贴板,然后将包含重音符号的文本粘贴到表单中?

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

解决方法

您可以在python中尝试将其复制到剪贴板中所需的文本,然后将其粘贴。它正在使用python 3.8。您也可以尝试。如果您遇到任何问题,请告诉我。

import pyperclip
pyperclip.copy('Text to be copied to the clipboard.')
clipboard_text= pyperclip.paste()
print(clipboard_text)