Search code examples
rubyselenium-webdriverwatir

Interacting with ace editor using selenium programmatically


I'm trying to do some web scraping with selenium-webdriver. The particular page uses the ace editor for syntax highlighting. The problem is that I can enter text using

driver.get "http://codetable.org"
elem = driver.find_element(:css, "#editor textarea")
elem.send_keys "Hello"

but I can't clear the text that is once entered. elem.clear has no impact on the page.

Is there some way I can delete the text that is on the screen programmatically? I suspect this is because of the extra css that ace adds. I'm using ruby 1.9.3.

I've also tried this

irb(main):035:0> driver.find_element(:css, ".ace_content").clear
Selenium::WebDriver::Error::UnknownError: Element must be user-editable in order to clear it.
    from [remote server]

Solution

  • It looks like when a value is inputted into the textarea, it is applied to another span. The textarea always has a blank value, which explains why clear does not work appear to do anything.

    If you want to clear the text, I think you might have to use keyboard shortcuts - ctrl+a and then delete. Try:

    elem.send_keys [:control, 'a'], :delete