I have the span:
<span disabled="disabled">Edit Member</span>
When I try to get the value of the disabled
attribute:
page.in_iframe(:id => 'MembersAreaFrame') do |frame|
expect(page.span_element(:xpath => "//span[text()='Edit Member']", :frame => frame).attribute('disabled')).to eq("disabled")
end
I get:
expected: "disabled"
got: "true"
How do I get the value of specified attribute instead of a boolean value?
The Page-Object gem's
attribute
method does not do any formatting of the attribute value. It simply returns what is returned from Selenium-WebDriver (or Watir-Webdriver).In the case of boolean attributes, this means that true or false will be returned. From the Selenium-WebDriver#attribute documentation:
As you can see, the "disabled" attribute is included in this list and thus returns a boolean.
If you really want to check the actual attribute value, you will have to parse the HTML. Unless the HTML is simple, I would suggest using Nokogiri (or other HTML parser) rather than writing your own. In Nokogiri: