Python Forum
How to send keys at beginning of textbox using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send keys at beginning of textbox using python
#1
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
Reply
#2
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.
Reply
#3
Hey Thanks a lot, it was almost slipped out of my mind. Thanks a lot again
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send unicode string encoded in utf-8 in http request in Python MaverinCode 1 32,363 Nov-08-2020, 06:45 AM
Last Post: JaiM
  Send Keys Error? AgileAVS 0 1,561 Oct-06-2020, 07:53 AM
Last Post: AgileAVS
  Code example for entering input in a textbox with requests/selenium object peterjv26 1 1,677 Sep-26-2020, 04:34 PM
Last Post: Larz60+
  Just beginning with Selenium JLogan3o13 2 1,817 Mar-22-2020, 05:25 PM
Last Post: JLogan3o13
  Python Rest API Public/Secret Keys Authentication Nonce dn237 1 2,874 Oct-31-2019, 02:07 AM
Last Post: dn237

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020