This is a migrated thread and some comments may be shown as answers.

Attributes within an element.

1 Answer 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SD
Top achievements
Rank 1
SD asked on 10 Jan 2011, 02:50 AM
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....

Ta.


 

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 12 Jan 2011, 05:23 AM
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!


Regards,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
SD
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Share this question
or