Hi everyone,
As you know, we can get the attribute value by the index, but there is a way to get the attribute by the "attribute name" instead of the Index? Because the index is not the same in the different browsers.
I've tried it, but nothing :(
Could someone please help me to see if this is possible?
Thanks,
Juan
                                As you know, we can get the attribute value by the index, but there is a way to get the attribute by the "attribute name" instead of the Index? Because the index is not the same in the different browsers.
I've tried it, but nothing :(
Could someone please help me to see if this is possible?
Thanks,
Juan
4 Answers, 1 is accepted
0
                                Hello Juan,
See here for more common HTML Find Expressions and here for more in-depth information.
Kind regards,
Anthony
the Telerik team
                                        What type of element are you trying to locate? Is it HTML, Silverlight, or WPF?
Here is a basic example for an HTML Anchor. By using Find.ByExpression you can use any attribute you like:
HtmlAnchor a = Find.ByExpression<HtmlAnchor>("tagname=a", "href=//en.wikipedia.org/");See here for more common HTML Find Expressions and here for more in-depth information.
Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
                                
                                                    Juan
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 10 May 2012, 03:07 PM
                                            
                                        Hi Anthony,
Basically I want to get the attributes by the "attribute name". Example:
I have a link with the text: "Go to Google", so I want to get its attribute by the name, no by the index:
?myManager.ActiveBrowser.Find.ByAttributes("Go to Google").Attributes
Count = 3
[0]: {(Attribute name='lang', value='en')}
[1]: {(Attribute name='class', value='google_link')}
[2]: {(Attribute name='xmlns', value='http://www.google.com')}
As you can see, I have three attributes for that element. Right now, I'm able to get the attribute value by the attribute index:
?myManager.ActiveBrowser.Find.ByAttributes("Go to Google").Attributes[2].Value
"http://www.google.com"
My question is: Is there a way to get the attribute value by the attribute name? Something like this:
?myManager.ActiveBrowser.Find.ByAttributes("BMW").Attributes["xmlns"].Value
"http://www.google.com"
Does my question make sense?
Thanks,
Juan
                                        Basically I want to get the attributes by the "attribute name". Example:
I have a link with the text: "Go to Google", so I want to get its attribute by the name, no by the index:
?myManager.ActiveBrowser.Find.ByAttributes("Go to Google").Attributes
Count = 3
[0]: {(Attribute name='lang', value='en')}
[1]: {(Attribute name='class', value='google_link')}
[2]: {(Attribute name='xmlns', value='http://www.google.com')}
As you can see, I have three attributes for that element. Right now, I'm able to get the attribute value by the attribute index:
?myManager.ActiveBrowser.Find.ByAttributes("Go to Google").Attributes[2].Value
"http://www.google.com"
My question is: Is there a way to get the attribute value by the attribute name? Something like this:
?myManager.ActiveBrowser.Find.ByAttributes("BMW").Attributes["xmlns"].Value
"http://www.google.com"
Does my question make sense?
Thanks,
Juan
0
                                Accepted
Hello Juan,
I accessed individual attributes from the element with the following code:
 
And here's the log output:
Greetings,
Anthony
the Telerik team
                                        Given the following HTML:
<a lang="en" class="google_link" xmlns="http://www.google.com">Go to Google</a>I accessed individual attributes from the element with the following code:
Element e = Find.ByTagIndex("a", 0);Assert.IsNotNull(e);Log.WriteLine(e.Attributes.Single(a => a.Name == "lang").Value);Log.WriteLine(e.Attributes.Single(a => a.Name == "class").Value);Log.WriteLine(e.Attributes.Single(a => a.Name == "xmlns").Value);And here's the log output:
Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
                                
                                                    Juan
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 11 May 2012, 05:46 PM
                                            
                                        That is exactly that I was found :)
Thanks a lot Anthony!
                                        Thanks a lot Anthony!