这是当我尝试访问网页中隐藏的文本字段时得到的错误。我使用以下命令浏览页面:
irb(main):184:0> browser.text_fields1.set“嘿,伙计”
WIN32OLERuntimeError: (in OLE method 'focus': )
`OLE error code:800A083E in htmlfile` `Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus. HRESULT error code:0x80020009 Exception occurred. from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/input_elements.rb:294:in 'method_missing' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/input_elements.rb:294:in 'set' from (irb):184 from C:/Ruby193/bin/irb:12:in 'main>'`提前感谢!
发布于 2012-06-15 21:03:39
当您手动使用浏览器时,如何处理文本字段?
您需要首先触发使文本字段可见的事件。然后,您可以使用您尝试过的代码在文本字段中输入。
发布于 2014-06-19 01:37:35
如果您查看跟踪,就会发现这是因为您正在尝试更新不可编辑或不可见的字段。如果你使用的是Watir "Classic“(仅限IE),你可以这样写:
require 'watir'
.
.
.
browser.text_fields[1].value = "Hey man" 但是,如果您使用的是其他浏览器/驱动程序,这也不会起作用。在浏览器的隐藏/不可编辑字段中,您必须使用javascript来执行此操作:
browser.execute_script("var elem = document.getElementById('your_textfield_id'); elem.value = 'Hey man';")这很烦人,但很有意义,因为它不能被用户编辑,也不能通过键盘来“设置”。
https://stackoverflow.com/questions/11050545
复制相似问题