watir: How do I enter a value in a form, without submitting the form with watir?

StackOverflow https://stackoverflow.com/questions/1677418

  •  16-09-2019
  •  | 
  •  

Question

I have a simple login form that has 2 text fields and a button. I can set the text of the username field just fine. When I set the password field however, the form automatically submits, and I get an error.

From IRB:

irb(main):008:0> ie.text_field(:name, "j_password").set("password")
WIN32OLERuntimeError: unknown property or method `value'
    HRESULT error code:0x80070005
      Access is denied.
        from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3431:in `method_missing'
        from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3431:in `doKeyPress'
        from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3427:in `each'
        from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3427:in `doKeyPress'
        from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3393:in `set'
        from (irb):8
irb(main):009:0> ie.text_fields.each {|x| puts x }
type:         text
id:
name:         j_username
value:
disabled:     false
length:       20
read only:    false
type:         password
id:
name:         j_password
value:
disabled:     false
length:       20
read only:    false

Any ideas why the error, or why the form is being submitted?

Note: I can set the fields just fine without the form being submitted using perl, vbscript, python, autoit, etc.

Was it helpful?

Solution

I could tell you more if you posted relevant HTML or link (if page is public), but my guess is that entering password fires JavaScript event that submits the form. Access is denied. could mean that there is a frame, and IE does not allow access to it (http://wiki.openqa.org/display/WTR/Frames).

Maybe this would help:

ie.text_field(:name, "j_password").value=("password")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top