Python: Selenium write in the text box of a form

20,006

The text area is inside an iframe - switch to it, find the element and send keys to it:

driver.switch_to.frame("textarea_iframe")
driver.find_element_by_id("textarea_body").send_keys("test")

Note that to delete the existing text in the text area, just pre-select it all:

text_area = driver.find_element_by_id("textarea_body")
text_area.send_keys(Keys.CONTROL, "a")  # or Keys.COMMAND on Mac
text_area.send_keys("test")

Additionally, if you would need to go back to the main content, use:

driver.switch_to.default_content()
Share:
20,006
TJ1
Author by

TJ1

Updated on July 09, 2022

Comments

  • TJ1
    TJ1 almost 2 years

    I am trying to write in the text box in here. It is the box that on its right hand it says "Paste your text here".

    I guess my question is how to find the item, for example by id, of the box that I should send text there in selenium driver?

    I tried something like:

    item = driver.find_element_by_css_selector("form#text_processor input[name=process_this]")
    item.send_key("Test!")
    

    But when I do that I get this error message:

    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":"form#text_processor input[name=process_this]"}
    

    I appreciate any help on this.