watir / watir_meta

Former watir.gem that referenced both watir-webdriver and watir-classic
http://watir.com
Other
407 stars 45 forks source link

Set value from css selector. #7

Closed hemanth closed 11 years ago

hemanth commented 11 years ago
@browser.elements(:css=>"input[type=password]").each {|x| p x.class}
WIN32OLE
WIN32OLE

Why is it a WIN32OLE?

@browser.elements(:css=>"input[type=password]").each {|x| x.value = "test"}
# It works fine in irb, but : Unknown method value= for....from the script 
jarmo commented 11 years ago

Fixed https://github.com/watir/watir-classic/commit/184d68e33c80a437a6061d9d4092ae47bda9fa79

Thanks!

jarmo commented 11 years ago

I don't have any ideas why it works in irb for you :)

You'd also have to call #to_subtype to convert to Watir::TextField so you could use #set.

For example:

@browser.elements(:css=>"input[type=password]").each { |element| element.to_subtype.value = "test"}

However, i would not use #elements and :css locators ever since it is the slowest combination possible.

I would use #text_fields instead:

@browser.text_fields.each { |field| field.value = "test"}

If it is really important to just set value to password fields, then i'd do like this:

@browser.text_fields.select { |field| field.type == "password" }.each { |field| field.value = "test"}