Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 577
amulllb Avatar asked Aug 06 '12 21:08

amulllb


People also ask

How do you select all in a text box in Selenium?

New! Save questions or answers and organize your favorite content. Learn more.

How do you press CTRL A in Selenium?

We can also perform a CTRL+A press by simply using the sendKeys() method. We have to pass Keys. CONTROL along with the string A by concatenating with +, as an argument to the method.

How do you use CTRL C and CTRL V in Selenium automation?

Copy & Paste Text: When we need to copy some text from one text box to another, we select the text by pressing "CTRL+A" they copy the text using "CTRL+C" and paste the text in the new text box by simply clicking in the text box and pressing keys "CTRL+V".


1 Answers

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

el = self.selenium.find_element_by_name(name)
el.clear()
like image 69
starenka Avatar answered Oct 05 '22 04:10

starenka