Python Forum

Full Version: How to send keys at beginning of textbox using python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi,

I have some text that i wish to enter via selenium into a webpage but my problem i want to insert them at beginning of the text as right now of there is already text into the text box it inserts my text at the bottom.

data_reference = driver.find_element_by_xpath('//*[@id="editdetails_frm"]/table/tbody/tr[24]/td[3]/textarea'+"\n")
        data_reference.send_keys(str(ele[1]))
        data_reference1 = driver.find_element_by_xpath('//*[@id="edit_detail[22]"]')
        data_reference1.click()
above is snippet of my code. Help is appreciated.Please dont mind the indentations i am trying to level them
Hello, so if I understand your problem correctly, you want to keep the text in the textarea but enter some string at the beginning:
data_reference = driver.find_element_by_xpath('//*[@id="editdetails_frm"]/table/tbody/tr[24]/td[3]/textarea'+"\n")

text_in_textarea = data_reference.text
data_reference.clear()
data_reference.send_keys(str(ele[1]) + text_in_textarea)

data_reference1 = driver.find_element_by_xpath('//*[@id="edit_detail[22]"]')
data_reference1.click()
I think you just need to save the text that's already in, clear the textarea and enter your string together with the text that was there before.
Hey Thanks a lot, it was almost slipped out of my mind. Thanks a lot again