I’m working through a Selenium test where I want to assert a particular HTML node is an exact match as far as what attributes are present and their values (order is unimportant) and also that no other attributes are present. For example given the following fragment:
<input name="test" value="something"/>
I am trying to come up with the a good way of asserting its presence in the HTML output, such that the following (arbitrary) examples would not match:
<input name="test" value="something" onlick="doSomething()"/><input name="test" value="something" maxlength="75"/><input name="test" value="something" extraneous="a" unwanted="b"/>
I believe I can write an XPath statement as follows to find all of these, for example:
//input[value='something' and @name='test']
But, I haven’t figured out how to write in such a way that it excludes not exact matches in a generalize fashion. Note, it doesn’t have to be an XPath solution, but that struck me as the most likely elegant possibility.
How about testing that the
valueandnameattributes are present, and that the total number of attributes is exactly 2: