简体   繁体   中英

I want to copy dynamically generated content from a textarea with selenium

http://eemaata.com/font2unicode/Encoder/unicode2font.php5 this is a website where we can convert unicode text to Anu Script Manager version (which is used for printing purposes). so what I am trying to do is 1. open website 2. paste the clipboard text into unicode text field (I will have the Unicode text copied to clipboard before running the selenium script) 3. click on Anu7 (dropdown) so it will convert the text and shows in a textarea 4. select all the text in that textarea and Copy that content

everything is perfectly working until generating anu7 text.. but I couldn't copy that content.. what can I do to get that content into my clipboard?

I tried to get the posTextOut.text after generating the text but no luck because the generated text is not showing in the textarea (I don't know why). I tried sending keys ctrl+a, ctrl+c but they are not working either. any help would be appreciated.. thanks

=========================

my code look like this

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

driver_path = 'C:\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path)
driver.get('http://kolichala.com/font2unicode/Encoder/unicode2font.php')
driver.implicitly_wait(20)
driver.maximize_window()

# Variables
unicode_input = driver.find_element_by_id('posTextIn')
anu7_output = driver.find_element_by_id('posTextOut')
anu7_selector = driver.find_element_by_xpath('//*[@id="aaa2"]/option[3]')

# pasting unicode text
unicode_input.send_keys(Keys.CONTROL + 'v')
# selecting anu7 version
anu7_selector.click()
driver.implicitly_wait(5)
# trying to copy the content
anu7_output.send_keys(Keys.CONTROL + 'a')
anu7_output.send_keys(Keys.CONTROL + 'c')

you need to add some waits between sending keys and clicking the transform button but then it shuld work

unicode_input = bot.driver.find_element_by_id('posTextIn')
anu7_output = bot.driver.find_element_by_id('posTextOut')
anu7_selector = bot.driver.find_element_by_xpath('//*[@id="aaa2"]/option[3]')
unicode_input.send_keys('Hello')
time.sleep(0.5)
bot.driver.find_element_by_id("transform").click()
print('printing output')
value = anu7_output.get_attribute('value')
print(value)

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