Select all text in a textbox Selenium RC using Ctrl + A

12,206

I'm using clear() in WebDriver without any hassle...

el = self.selenium.find_element_by_name(name)
el.clear()
Share:
12,206

Related videos on Youtube

amulllb
Author by

amulllb

Updated on September 15, 2022

Comments

  • amulllb
    amulllb over 1 year

    I am trying to select all the text in a textbox in order to clear the textbox. I am using Ctrl+A to do this using the following Python 2.7 code on Selenium RC standalone 2.20.0.jar Server on Windows 7 firefox:

    from selenium import selenium
    s = selenium('remote-machine-ip', 4444, '*chrome', 'http://my-website-with-textbox')
    locator = 'mylocator-of-textbox'
    s.open()
    s.type(locator, 'mytext')
    s.focus(locator)
    s.control_key_down()
    s.key_down(locator, "A")
    s.key_press(locator, "A")
    s.key_up(locator, "A")
    s.control_key_up()
    
    # Nothing happens here... I cannot see the text getting selected...
    
    # Nothing gets cleared here except the last char
    s.key_down(locator, chr(8))  # Pressing backspace
    s.key_press(locator, chr(8))
    s.key_up(locator, chr(8))
    

    Any help? Thanks, Amit

  • amulllb
    amulllb over 11 years
    I am not using WebDriver, because I am using Selenium RC... Any idea how to do the same in Selenium RC... I don't want to move to WebDriver now...
  • starenka
    starenka over 11 years
    If .clear is not present in RC (I think it is), how about .type("") ?
  • amulllb
    amulllb over 11 years
    I tried .type("A") in place of .key_down/press/up().... But I get the following exception: type not supported immediately after call to controlKeyDown() or altKeyDown() or metaKeyDown()