Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Unable to type in a content editable body #2442

Closed
lukeis opened this issue Mar 3, 2016 · 13 comments
Closed

Unable to type in a content editable body #2442

lukeis opened this issue Mar 3, 2016 · 13 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 2442

What steps will reproduce the problem?
1. Call sendKeys(text) on a content editable body

What is the expected output? What do you see instead?
I expect the text to be visible in the body but nothing is printed. 

Selenium version:
OS: Mac OSX 10.6.8
Browser: Firefox
Browser version: 4, 5 and 6 

I have attached a small test case that uses the code provided at http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_type_into_a_contentEditable_iframe?
that fails with or without an iframe.

Reported by nguyen.improved on 2011-09-12 01:21:23


- _Attachment: [iframe.html](https://storage.googleapis.com/google-code-attachments/selenium/issue-2442/comment-0/iframe.html)_ - _Attachment: [test.html](https://storage.googleapis.com/google-code-attachments/selenium/issue-2442/comment-0/test.html)_ - _Attachment: [TestContentEditable.java](https://storage.googleapis.com/google-code-attachments/selenium/issue-2442/comment-0/TestContentEditable.java)_
@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Interestingly if I pause the test and manually click in the body, sendKeys works for
the non-iframe case. This doesn't work for the iframe case.

Reported by nguyen.improved on 2011-09-12 01:22:27

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

The test works when run against Firefox 3.5 and 3.6.

Reported by nguyen.improved on 2011-09-12 01:23:32

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Add contentEditable.click() before contentEditable.sendKeys("something")

It is exactly what a user does.

Reported by barancev on 2011-09-16 21:47:47

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by barancev on 2011-10-04 09:25:55

  • Labels added: Component-WebDriver

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Trying 

    private void typeIntoBody(WebDriver driver)
    {
        ((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<br>'");
        final WebElement contentEditable = driver.findElement(By.id("test"));
        contentEditable.click();
        contentEditable.sendKeys("something");
        assertEquals("something", contentEditable.getText());
    }

doesn't work for my test cases.

Reported by nguyen.improved on 2011-10-05 06:45:38

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Still not working as of 2.15.0 on Firefox 8.

Reported by jaie.wilson on 2011-12-14 02:49:31

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Still not working on:

Selenium version: 2.21.0
OS: XP SP3
Browser: Firefox
Browser version: 12.0

However, this work-around does the job for now:

if (runningInFirefox()) {
  // Send the keys regardless since the events seem to fire
  contentEditable.sendKeys(value);
  ((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<p>" + value
+ "</p>'");
} else {
...

Reported by RedYetiDave on 2012-05-18 15:17:27

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

If you are not on MacOS, try to execute this code:

FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.tinymce.com/tryit/full.php");
WebElement iframe = driver.findElement(By.id("content_ifr"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.id("tinymce"));
tinymce.clear();
tinymce.sendKeys("Hello, tinymce!");

I've checked it works as expected with selenium 2.22 and firefox 12 with native events
enabled.

On MacOS native events are not implemented yet.

Reported by barancev on 2012-06-02 18:44:34

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thank you comment #7.  I tried all sorts of things (clicking in the body, clicking in
the paragraph, enabling native events, etc).  Nothing worked until I saw your JavaScript
technique.

Selenium version: 2.23.0
OS: Mac OSX Lion
Browser: Firefox 13.0.1

Reported by kielnicholls on 2012-08-07 18:49:04

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I am having this happen with  Firefox 14.0.1,
OSX Lion
Selenium 2.25.0

I cannot get any of the workaround working:

        editable=self.driver.find_element_by_class_name("editable")
        editable.click()

        comment="test posting a comment @" + str(self.timestamp)
        time.sleep(1)
        editable.send_keys(comment)
        if (self.browser == "firefox"):
            self.driver.execute_script("document.body.innerHTML = '<p>" + comment +
"</p>'")

it works perfectly in chrome, in FF with workaround it shows text on screen but the
rest of the page disapears

Reported by alon@livefyre.com on 2012-08-21 00:22:34

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I've created a separate issue 5671 on native events for MacOS.
Closing this issue as fixed because in general selenium can type into contenteditable
elements.

Reported by barancev on 2013-05-19 16:23:29

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I have tried all possible solutions for entering Text into editor area.
Please find the attached screenshot for details

Reported by harip315 on 2013-12-05 14:53:44


- _Attachment: texteditorviewsource.PNG
![texteditorviewsource.PNG](https://storage.googleapis.com/google-code-attachments/selenium/issue-2442/comment-12/texteditorviewsource.PNG)_

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:13:40

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant