SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

Copy and Paste via ActionBuilder API fails in ContentEditable div. #5946

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 5946

Copying and pasting text within a ContentEditable div using the ActionBuilder
API does not work.

Steps to Reproduce
1. Focus the text area or contenteditable div.
2. Highlight some text.
3. Copy the text using [ctrl/cmd] + c.
4. Move the cursor to remove highlighting.
5. Paste the text using [ctrl/cmd] + v.

What is the expected output? What do you see instead?
Expected: The copied text was pasted at the cursor position.
Actual: In Chrome, no text is pasted at the cursor position. In
Firefox, whatever text is already in my system clipboard is pasted.

Selenium version:
- 'selenium-webdriver' gem, 2.33.0
- chromedriver, 26.0.1383.0 [note that this issue also occurs in firefox, and
I'm using whatever driver is bundled with the ruby bindings]
Browser: Chrome
Chrome Version: 28.0.1500.71
Browser: Firefox
Firefox Version: 22.0

I've posted a reduced test case demonstrating the issue here:
https://gist.github.com/byronm/82c1c0f227b6cd54ec73
I'm most interested in the contenteditable case, but I've included a commented
out textarea in the HTML for convenience.

Thanks for any help or ideas!

Reported by byronner on 2013-07-18 03:34:59

lukeis commented 8 years ago

Reported by a.u.savchuk on 2013-07-20 08:29:37

lukeis commented 8 years ago
Update: I upgraded to the latest ChromeDrivers.

I'm running ChromeDriver v2.1 (v2.1.210398) on OSX 10.7.5 and the test case still fails.
I'm running ChromeDriver v2.1.210652 on Windows 7 and it passes.

Firefox fails on both OSX and Windows. Internet Explorer fails as well. Happy to provide
versioning information and logs for any combination requested.

Thanks.

Reported by byronner on 2013-07-25 22:47:26

lukeis commented 8 years ago
While I'm trying to reproduce the issue I want to say that your scenario is overcomplicated
:)

browser = Selenium::WebDriver.for :firefox

begin
  browser.get "file://#{path}"
  editable = browser.find_element :id, "editable"
  editable.send_keys "abc"
  # Copy
  editable.send_keys(:control, "a")
  editable.send_keys(:control, "c")
  # Paste
  editable.send_keys(:control, "v", "v", "v")
ensure
  #browser.quit
  File.delete path
end

Note that on Windows you have to use :control instead of :command

I checked this code works in Chrome and Firefox. IE can't work with file:// URLs, deploy
the page to a server and I'm sure IE will work too.

Reported by barancev on 2013-07-30 20:58:06

lukeis commented 8 years ago
Thank you for looking into this issue; I really appreciate you taking the time to help
out.

Is there a specific reason that you've implemented the paste as editable.send_keys(:control,
"v", "v", "v")? In my view, this changes the test case. I do not wish to paste the
text three times, overwriting the selection the first time. I simply want to append
the pasted text once, which is why in my original test case I remove the highlighting
first. Making that modification to your code yields the following paste command:

editable.send_keys :arrow_right # Remove highlighting
editable.send_keys(:control, "v") # Paste

Regardless of whether I use this implementation or editable.send_keys(:control, "v",
"v", "v"), I'm seeing buggy behavior. Here's the results I get with both implementations:

__OSX 10.7.5__
Firefox 22:

editable.send_keys :arrow_right
editable.send_keys(:command, "v")
Expected text: "abcabc"
Actual text: "abc abc "

editable.send_keys(:command, "v", "v", "v")
Expected text: "abcabcabc"
Actual text: "abc abc abc "

Chrome 28:

editable.send_keys :arrow_right
editable.send_keys(:command, "v")
The text is not pasted.

editable.send_keys(:command, "v", "v", "v")
The text is not pasted.

__Windows 7__
Chrome 28:
Works as expected

Firefox 22:

editable.send_keys :arrow_right
editable.send_keys(:control, "v")
Expected: "abcabc"
Actual: "abc abc "

editable.send_keys(:control, "v", "v", "v")
Expected text: "abcabcabc"
Actual text: "abc abc abc "

Internet Explorer:
Works as expected with your simplified code. With my original code it does not. I've
found that file:// URL's work fine with IE, though that is a limitation in Safari.
I think the difference must be due to me using the ActionBuilder api explicitly and
your test code here using it implicitly via send_keys. I'll look into that more; it
may be worthy of its own bug.

Thanks again for looking at this. Let me know if you have any questions about this
reply, or if I can help debug/provide any further info.

Reported by byronner on 2013-07-30 22:08:45

lukeis commented 8 years ago
Yes, my bad, "paste three times" was my modification that allowed me to see more obviousely
that pasting works.

Reported by barancev on 2013-07-30 22:25:34

lukeis commented 8 years ago
I'm a bit surprised that chording keys in the way barancev does here actually works.
I would expect to have to do:

  element.send_keys([:command, 'v']) 

in order to get the keys pressed at the same time. 

Reported by jari.bakken on 2014-08-13 09:29:36

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:45:54