rubyrspecwatir-webdriverpage-object-gemrspec-expectations

Make sure that attribute "disabled" equals to "disabled"


I have a span with attribute "disabled"

<span disabled="disabled" id="Apply">

If I try to use next expectation:

expect(page.spnApply_element).to have_attributes(:disabled => "disabled")

I get an error:

expected #<Watir::Span:0x..fe4257660 located=false selector={:id=>"Apply", :tag_name=>"span"}> to respond to :disabled with 0 arguments

How to use expectation which validate "disabled" attribute that it equals to disabled?


Solution

  • The have_attributes method is an RSpec matcher used to test Ruby objects. To test the actual HTML attribute, you should be able to use the Watir method attribute_value like so:

    expect(page.spnApply_element.attribute_value("disabled")).to be