WebDriver claiming editable element is not editable
Question: I'm running a simple test with Selenium WebDriver and Python to send/verify
receipt of email.

Once I switch to the iframe containing the message body and locate the
editable body element and try to clear it out, the following exception is
thrown:

    
    
    Traceback (most recent call last):
    driver.find_element_by_xpath("//body[@role='textbox']").clear()
    selenium.common.exceptions.WebDriverException: Message: 'Element must be user-editable in order to clear it.'
    

Here is the script used to create an email:

    
    
    driver.find_element_by_name("to").clear()
    driver.find_element_by_name("to").send_keys("toemailaddy@gmail.com")
    localtime = time.asctime( time.localtime(time.time()) )
    subj = ("TEST - " + localtime)
    print(subj)
    driver.find_element_by_name("subjectbox").clear()
    driver.find_element_by_name("subjectbox").send_keys(subj)
    body = ("TEST")
    bodyFrame = driver.find_element_by_xpath("//td[@class='Ap']//iframe")
    driver.switch_to_frame(bodyFrame)
    driver.find_element_by_xpath("//body[@role='textbox']").clear()
    driver.find_element_by_xpath("//body[@role='textbox']").send_keys(body)
    driver.find_element_by_xpath("/div[@role='button' and contains(text(), 'Send')]").click()
    driver.find_element_by_link_text("Inbox (1)").click()
    

However, the message body is explicitly user-editable. Below I've included a
snippet of the message body HTML that I have WebDriver directed to within the
iframe nested in the td class "Ap" that explicitly shows that it's editable.

    
    
    <body id=":3" class="editable LW-avf" style="min-width: 0px; width: 437px; 
    border: 0px none; margin: 0px; background: none repeat scroll 0% 0% transparent;
    height: 100%; overflow: hidden; direction: ltr; min-height: 121px;" hidefocus="true" 
    g_editable="true" role="textbox">
    

IDE is able to access all of the elements, but what could be keeping WebDriver
from accessing them?

**EDIT**

Well, I just found out what was causing the exception:

I found that by removing the following line from the script allowed WebDriver
to write in the textbox.

    
    
    driver.find_element_by_xpath("//body[@role='textbox']").clear()
    

Though I wonder why it would throw the exception that the element must be
editable, but allows it to send_keys to the element without issue?


Answer: Have you tried with [Action Chains](http://selenium-
python.readthedocs.org/en/latest/api.html#module-
selenium.webdriver.common.action_chains)?

    
    
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.keys import Keys
    
    driver.switch_to_frame(bodyFrame)
    
    ActionChains(driver).send_keys(Keys.CONTROL, "a").perform()
    ActionChains(driver).send_keys("Test").perform()
    
    # alternative:
    # body_ele = driver.find_element_by_xpath("//body[@role='textbox']")
    # body_ele.send_keys(Keys.CONTROL, 'a')
    # body_ele.send_keys("Test")
    

In C#, `IWebElement.Clear` says "If this element is a text entry element, the
Clear() method will clear the value. It has no effect on other elements. Text
entry elements are defined as elements with INPUT or TEXTAREA tags.".
Similarly, in [python source
code](https://code.google.com/p/selenium/source/browse/py/selenium/webdriver/remote/webelement.py#61),
it says "Clears the text if it's a text entry element.", while in your case,
`body` is not a text entry element.

