Chrome changed the JS behavior of Selection#addRange
This commit is contained in:
parent
084cf8eded
commit
07f14cf707
|
@ -77,16 +77,20 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
elsif native.attribute('isContentEditable')
|
elsif native.attribute('isContentEditable')
|
||||||
#ensure we are focused on the element
|
#ensure we are focused on the element
|
||||||
native.click
|
native.click
|
||||||
|
|
||||||
script = <<-JS
|
script = <<-JS
|
||||||
var range = document.createRange();
|
var range = document.createRange();
|
||||||
|
var sel = window.getSelection();
|
||||||
arguments[0].focus();
|
arguments[0].focus();
|
||||||
range.selectNodeContents(arguments[0]);
|
range.selectNodeContents(arguments[0]);
|
||||||
window.getSelection().addRange(range);
|
sel.removeAllRanges();
|
||||||
|
sel.addRange(range);
|
||||||
JS
|
JS
|
||||||
driver.execute_script script, self
|
driver.execute_script script, self
|
||||||
|
|
||||||
if (driver.options[:browser].to_s == "chrome") ||
|
if (driver.options[:browser].to_s == "chrome") ||
|
||||||
(driver.options[:browser].to_s == "firefox" && !driver.marionette?)
|
(driver.options[:browser].to_s == "firefox" && !driver.marionette?)
|
||||||
# chromedriver raises a can't focus element if we use native.send_keys
|
# chromedriver raises a can't focus element for child elements if we use native.send_keys
|
||||||
# we've already focused it so just use action api
|
# we've already focused it so just use action api
|
||||||
driver.browser.action.send_keys(value.to_s).perform
|
driver.browser.action.send_keys(value.to_s).perform
|
||||||
else
|
else
|
||||||
|
|
|
@ -122,23 +122,25 @@ Capybara::SpecHelper.spec "node" do
|
||||||
expect(@session.first('//textarea[@readonly]').set('changed')).to raise_error(Capybara::ReadOnlyElementError)
|
expect(@session.first('//textarea[@readonly]').set('changed')).to raise_error(Capybara::ReadOnlyElementError)
|
||||||
end if Capybara::VERSION.to_f > 3.0
|
end if Capybara::VERSION.to_f > 3.0
|
||||||
|
|
||||||
it 'should allow me to change the contents of a contenteditable element', requires: [:js] do
|
context "with a contenteditable element", requires: [:js] do
|
||||||
@session.visit('/with_js')
|
it 'should allow me to change the contents' do
|
||||||
@session.find(:css,'#existing_content_editable').set('WYSIWYG')
|
@session.visit('/with_js')
|
||||||
expect(@session.find(:css,'#existing_content_editable').text).to eq('WYSIWYG')
|
@session.find(:css,'#existing_content_editable').set('WYSIWYG')
|
||||||
end
|
expect(@session.find(:css,'#existing_content_editable').text).to eq('WYSIWYG')
|
||||||
|
end
|
||||||
|
|
||||||
it 'should allow me to set the contents of a contenteditable element', requires: [:js] do
|
it 'should allow me to set the contents' do
|
||||||
@session.visit('/with_js')
|
@session.visit('/with_js')
|
||||||
@session.find(:css,'#blank_content_editable').set('WYSIWYG')
|
@session.find(:css,'#blank_content_editable').set('WYSIWYG')
|
||||||
expect(@session.find(:css,'#blank_content_editable').text).to eq('WYSIWYG')
|
expect(@session.find(:css,'#blank_content_editable').text).to eq('WYSIWYG')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should allow me to change the contents of a contenteditable elements child', requires: [:js] do
|
it 'should allow me to change the contents of a child element' do
|
||||||
@session.visit('/with_js')
|
@session.visit('/with_js')
|
||||||
@session.find(:css,'#existing_content_editable_child').set('WYSIWYG')
|
@session.find(:css,'#existing_content_editable_child').set('WYSIWYG')
|
||||||
expect(@session.find(:css,'#existing_content_editable_child').text).to eq('WYSIWYG')
|
expect(@session.find(:css,'#existing_content_editable_child').text).to eq('WYSIWYG')
|
||||||
expect(@session.find(:css,'#existing_content_editable_child_parent').text).to eq('Some content WYSIWYG')
|
expect(@session.find(:css,'#existing_content_editable_child_parent').text).to eq('Some content WYSIWYG')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue