Not able to use send_keys method to set the text of a division using Watir

754 views Asked by At

I have trouble setting the text of a division using the send_keys method. This is what I m trying to set:

d = browser.div(id: "editor").p.send_keys "Hello"
puts d

and

d = browser.div(id: "editor").send_keys "Hello"
puts d 

None of these works, error message is the following:

/Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/response.rb:71:in `assert_ok': {"errorMessage":"undefined is not an object (evaluating 'b.value.length')","request":{"headers":{"Accept":"application/json","Accept-Encoding":"gzip;q=1.0,deflate;q=0.6,identity;q=0.3","Connection":"close","Content-Length":"19","Content-Type":"application/json; charset=utf-8","Host":"127.0.0.1:8910","User-Agent":"Ruby"},"httpVersion":"1.1","method":"POST","post":"{\"value\":[\"Hello\"]}","url":"/value","urlParsed":{"anchor":"","query":"","file":"value","directory":"/","path":"/value","relative":"/value","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/value","queryKey":{},"chunks":["value"]},"urlOriginal":"/session/020fee40-13f2-11e5-8cd1-df1f4eb298ed/element/%3Awdc%3A1434436593166/value"}} (org.openqa.selenium.WebDriverException) (Selenium::WebDriver::Error::UnknownError)
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:78:in `new'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:78:in `create_response'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/default.rb:90:in `request'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:657:in `raw_execute'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:635:in `execute'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:438:in `sendKeysToElement'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/element.rb:145:in `send_keys'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/watir-webdriver-0.7.0/lib/watir-webdriver/elements/element.rb:321:in `block in send_keys'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/watir-webdriver-0.7.0/lib/watir-webdriver/elements/element.rb:574:in `element_call'
from /Users/alexwang/.rvm/gems/ruby-2.1.1/gems/watir-webdriver-0.7.0/lib/watir-webdriver/elements/element.rb:321:in `send_keys'
from nychinaren.rb:18:in `block in <main>'
from nychinaren.rb:16:in `each'
from nychinaren.rb:16:in `<main>'

And this is the division I am trying to insert in text enter image description here

enter image description here

1

There are 1 answers

0
Oleksandr Holubenko On

You can try do it, using execute_script it seems like:

p = browser.div(id: "editor").p
browser.execute_script('execute_script('arguments[0].innerHTML = "Hello";', p)