0

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')
kiku_here
  • 3
  • 3
  • You probably have to get the value, and not the text – Bendik Knapstad May 27 '20 at 06:53
  • how can I get the value in selenium ? anu7_output.value throws me an erro – kiku_here May 27 '20 at 06:59
  • yes. I need to get the value not the text of the item I tried to get the value by anu7_output.get_attribute('value') not showing anything. please help me.. – kiku_here May 27 '20 at 07:17
  • @BendikKnapstad with javascript it is working to get the value. but I want that with selenium (python) – kiku_here May 27 '20 at 07:20
  • I get it to work in my end: inn=bot.driver.find_element_by_id('posTextIn') out=bot.driver.find_element_by_id('posTextOut') inn.send_keys("hello") bot.driver.find_element_by_id("transform").click() out.get_attribute("value") '%hello' are you running headless? doubble check that you are actualy pasting stuff in the input feild – Bendik Knapstad May 27 '20 at 07:38
  • You are not clicking the transform button it seems: 'driver.find_element_by_id("transform").click()' – Bendik Knapstad May 27 '20 at 07:39
  • @BendikKnapstad pasting in is working fine and transform text is also working. But the issue is I can't get the converted data. that is the vlaue of posTextOut actually we dont need to click on transform button as we choose anu7 from the dropdown it will automatically converts the text given – kiku_here May 27 '20 at 07:47
  • @BendikKnapstad what do you mean by headless ? – kiku_here May 27 '20 at 07:50
  • i run your exact code, and it works using `anu7_output.get_attribute("value")` – Bendik Knapstad May 27 '20 at 07:56
  • and i notice it wont generate values if you try to select anu7 if that option is already selected. – Bendik Knapstad May 27 '20 at 07:57
  • @BendikKnapstad Strange, but why is it not working for me ? ---- I am storing the value in a variable and printing it .. but nothing is printing I tried with your code. gave me this error `NameError: name 'bot' is not defined` ------- and yeah it wont generate new text if we select anu7 again if it already selected. then we need to click on Transform button – kiku_here May 27 '20 at 08:00
  • sorry the bot part is just my wapper for selenium delete that part – Bendik Knapstad May 27 '20 at 08:01
  • @BendikKnapstad my New code look like this `driver = webdriver.Chrome(executable_path=driver_path) driver.get('http://kolichala.com/font2unicode/Encoder/unicode2font.php') 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]') unicode_input.send_keys('Hello') driver.find_element_by_id("transform").click() print('printing output') value = anu7_output.get_attribute('value') print(value)` Nothing printing in the console. am I missing anything ? – kiku_here May 27 '20 at 08:05
  • i needed to add some waits between sending keys and clicking the transform button but then it worked – Bendik Knapstad May 27 '20 at 08:10
  • i just added time.sleep(0.5) – Bendik Knapstad May 27 '20 at 08:10
  • are you getting the output in print ? – kiku_here May 27 '20 at 08:27
  • @BendikKnapstad I mean everything is working for me except the print(outputText) part... no errors shown. it just does nothing – kiku_here May 27 '20 at 08:33
  • Im getting the output yes: printing output %Hello – Bendik Knapstad May 27 '20 at 08:45
  • @BendikKnapstad \n YAY... I think time.sleep does the magic. or some of my commented code was messing everything... I now got it working by adding time.sleep(0.5) in a new python file.. THANKS A TON FOR YOUR VALUABLE TIME BROTHER. \n I now want that text in my clipboard. how can I do that with python ? (and can you please post your answer above in 'answer this question' ? so I can mark it best answer ?) – kiku_here May 27 '20 at 08:46
  • look at this one. it shuld help you with the clipboard thing https://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-windows-clipboard-from-python – Bendik Knapstad May 27 '20 at 08:57

1 Answers1

0

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)
Bendik Knapstad
  • 1,409
  • 1
  • 9
  • 18