我无法使用send_keys方法设置分区的文本。 这就是我想要设置的内容:
d = browser.div(id: "editor").p.send_keys "Hello"
puts d
和
d = browser.div(id: "editor").send_keys "Hello"
puts d
这些都不起作用,错误信息如下:
/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>'
这是我试图在文本中插入的部门
答案 0 :(得分:2)
您可以尝试使用execute_script
来执行此操作:
p = browser.div(id: "editor").p
browser.execute_script('execute_script('arguments[0].innerHTML = "Hello";', p)