This is the error I get when I try to access a hidden textfield in the webpage. I am navigating through the page using
irb(main):184:0> browser.text_fields[1].set "Hey man"
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>'
Thanks in advance!!!
How do you work with that text field when you manually use the browser?
You need to first trigger the event that causes the text field to be visible. Then you can input into the text field using the code you tried.
If you look at the trace, it happens because you are trying to update a non-editable or invisible field. If you are using Watir "Classic" (IE only) you can write:
require 'watir'
.
.
.
browser.text_fields[1].value = "Hey man"
however if you are using other browser / driver that won't work neither. In hidden/non-editable fields in browser you have to use javascript to do so:
browser.execute_script("var elem = document.getElementById('your_textfield_id'); elem.value = 'Hey man';")
Annoying, but makes sense since it's not editable by user, then can't be "set" by using keyboard.
User contributions licensed under CC BY-SA 3.0