Attributes within an element.

2 posts, 0 answers
  1. SD
    SD avatar
    62 posts
    Member since:
    Apr 2010

    Posted 09 Jan 2011 Link to this post

    Hi Guys, 

    I'm trying to write a simple test to find out whether a page is a read-only by checking if the attribute 'disable' is a part of a control's attribute (checkbox in this case).
    I've got 3 disabled check-boxes on the page I'm testing. They look like this:
    <input type="checkbox" disabled="disabled" name="assessmentForm:metCompletedPassedCourse" id="assessmentForm:metCompletedPassedCourse"/>

    So I 'Collecting' all 3....
    var checkBox = Manager.ActiveBrowser.Find.AllByAttributes<HtmlInputCheckBox>("type=checkbox");

    And then try to verify that 'disable' is an existing attribute of each one of the check boxes elements. 
    Assert.True(checkBox.All(item => item.Attributes.Contains( ?

    Could you pls advice what is the iAttribute value as I'm not able to complete the above assertion....


  2. Stoich
    Stoich avatar
    1 posts

    Posted 11 Jan 2011 Link to this post

    Hello Seth,

        this is a bit tricky because WebAii does recognize values for "disable". For instance your checkbox looks like this when we invoke the ToString() method on it. 
    HtmlInputCheckBox:<INPUT id=assessmentForm:metCompletedPassedCourse disabled type=checkbox name=assessmentForm:metCompletedPassedCourse>
    Notice how disabled is in there without a value assigned to it. Because of this you won't be able to find it as an attribute. 
    Instead I just check whether the String representation of the Checkbox contains " disabled ". Here's my code:

    foreach (HtmlInputCheckBox c in Manager.ActiveBrowser.Find.AllByAttributes<HtmlInputCheckBox>("type=checkbox")) {
                    Assert.IsTrue(c.ToString().Contains(" disabled ")); 
    *Note: I'm searching for " disabled " with whitespace before and after the word just to be 100% sure the element doesn't contain the string "disabled" else where in the definition (unlikely but still...).
    I ran this code against the HTML you provided - it worked.

    I this will get the job done - let me know if you have any more questions!

    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Back to Top