在我的一些测试中,我必须确认在设置某些标志时禁用某些select2下拉列表。为了证实这一点,我发现下面的策略似乎有效:
Assert.True(element.GetAttribute("disabled").Equals("true"));
当我检查元素时,我看到disabled="disabled"
。我的问题是为什么从GetAttribute = "true"
返回的字符串没有“禁用”?
答案 0 :(得分:7)
https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html
某些属性似乎只返回布尔值,无论实际值是“true”还是“false”。残疾人就是其中之一。链接页面列出了所有被认为是布尔值的属性,任何其他属性都应该返回属性的值。
引用链接页面中最相关的部分:
“以下被视为”布尔“属性,并将返回”true“或null:async,autofocus,autoplay,checked,compact,complete,controls,declare,defaultchecked,defaultselected,defer,已禁用,draggable,ends,formnovalidate,hidden,indeterminate,iscontenteditable,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,paused,pubdate,readonly,required,reversed, scoped,seamless,seek,selected,spellcheck,truespeed,willvalidate“。 [Selenium : WebElement.getAttribute()]