Currently this functionality does not exisits. However, I will work on a fix for this and try to post it quickly. You can however modify the MatchAtributes method in HTMLElementFindParams if you need this quickly.
Matthew M. Osborn
http://blog.osbornm.com
http://www.codingqa.com
http://weblogs.asp.net/asptest
"Change the world or go home."
We have decide that we will try as hard as we can not to modify the framework code directly, we want to be able to quickly add your upgrades without a slow merge process. The thought being we are adopting this so early we do not want to be out of the loop
for updates.
I did have a fix suggestion though :)
1) Mark TreatIdAs Obsolete.
2) Rename it to SearchMethodType (or some better name)
3) Use the new enum in the Find() method
4) Use the new Enum as optional in the Attributes.Add() method
The idea being I might want to mix and match attributes. Exact match on class, partial on href.
Michael Cowan
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
I see what you are suggesting, but I am testing remote pages that I do not have access direct access to. Maybe there is a way to insert my own scripts into the page before the browser gets it, but I would worry about my test scripts affecting the page.
The other problem is many of the elements I need to find don't have an id. For example:
I see what you are suggesting, but I am testing remote pages that I do not have access direct access to. Maybe there is a way to insert my own scripts into the page before the browser gets it, but I would worry about my test scripts affecting the page.
You can register the javascript and output from server.
Bober, Am I missing something important? I do not understand your ShowMessage(string message) method and how it relates to running a WebTestMethod. What I am trying to do is test a webpage where I do not have access to the webpage code. Lets say for Example
Google.com. Are you telling me that I can use some injected javascript against a site like google to figure out the classname? Would you mind please giving me at simple (but working) WebTestMethod that shows how to get the Google.com search button using Javascript?
If there is a way to insert javascript into the reponse from a page request I am going to be happy!
Michael Cowan
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
I see the confusion in the responses to my posts. I apologize for my horrible communication skills in this thread. Let me clear things up.
I know HOW to use javascript when I am developing my own ASP.NET web pages. I don't need any help writing javascript code or syntax (but thanks for the jquery link, its cool)
What I am confused on, is that a previous post made it sound like it is possible to use the ASP.NET QA Lightweight Test Automation Framework to test
http://google.com/index.html and use custom javascript INSIDE the test method (not on the google index.html page) to parse a classname.
I did not think it was possible to use javascript inside the C# test code to interact with webpages. If it is possible to inject javascript using this framework that would be AWESOME and I would love to know how to do it.
Michael Cowan
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
Michael, your suggestion sounds good and we are including it in our next release. Currently, its looking something like this (names may change):
<div>public enum MatchMethod</div> <div>{</div> <div> Literal,</div> <div> EndsWith,</div> <div> Contains,</div>
<div> Regex</div> <div>}</div> <div> </div> <div>public class HtmlAttributeMatch</div> <div>{</div> <div> public
string Name {get; set;}</div> <div> public string Value {get;set;}</div> <div> public MatchMethod ValueMatchMethod {get;set;}</div> <div> ...
}</div> <div> </div> <div>public class HtmlAttributeMatchCollection: List<HtmlAttributeMatch></div> <div>{</div> <div> public void Add(string name, string
value) {...}</div> <div> public void Add(string name, string value, MatchMethod valueMatchMethod) {...}</div> <div>}</div>
One of the tricky things is how to deal with the current TreadIdAs. I am thinking of completely removing it instead of deprecating it, I mean we can fix the tests on our side relatively easily. Would you be ok with this?
mcowan
Member
8 Points
42 Posts
How do you find elements when all you know is a part of its class?
Mar 15, 2009 11:03 PM|LINK
So here is the markup:
What I want to do it this (but instead of the Id, I want to use the classname.)
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
osbornm
Participant
914 Points
196 Posts
Microsoft
Re: How do you find elements when all you know is a part of its class?
Mar 16, 2009 11:25 PM|LINK
Currently this functionality does not exisits. However, I will work on a fix for this and try to post it quickly. You can however modify the MatchAtributes method in HTMLElementFindParams if you need this quickly.
http://blog.osbornm.com
http://www.codingqa.com
http://weblogs.asp.net/asptest
"Change the world or go home."
mcowan
Member
8 Points
42 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 16, 2009 11:37 PM|LINK
We have decide that we will try as hard as we can not to modify the framework code directly, we want to be able to quickly add your upgrades without a slow merge process. The thought being we are adopting this so early we do not want to be out of the loop for updates.
I did have a fix suggestion though :)
1) Mark TreatIdAs Obsolete.
2) Rename it to SearchMethodType (or some better name)
3) Use the new enum in the Find() method
4) Use the new Enum as optional in the Attributes.Add() method
The idea being I might want to mix and match attributes. Exact match on class, partial on href.
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
Bober Song -...
All-Star
34686 Points
2167 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 18, 2009 10:03 AM|LINK
Hi,
Why not use the Javascript to match the class string.
<a id="ccscript" class="bober song ccscript" href="http://www.ccscript.cn">ccscript</a> <script> var classes=document.getElementById("ccscript").className.split(' '); var bb=""; for(var i=0;i<classes.length;i++) bb+=classes[i]+"="; alert(bb); </script>< pre>Then you can get the class array.
If I have misunderstood your meaning, please feel free to let me know.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
mcowan
Member
8 Points
42 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 18, 2009 05:54 PM|LINK
I see what you are suggesting, but I am testing remote pages that I do not have access direct access to. Maybe there is a way to insert my own scripts into the page before the browser gets it, but I would worry about my test scripts affecting the page.
The other problem is many of the elements I need to find don't have an id. For example:
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
Bober Song -...
All-Star
34686 Points
2167 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 19, 2009 03:25 AM|LINK
Hi,
You can register the javascript and output from server.
public void ShowMessage(string message) { string strMessage = message; string strScript = "<script>alert('" + message + "'); </script>"; Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler; ParameterPage.RegisterStartupScript("alertmessage", strScript); }If you want to deal with the tag's class in the server,
you can use AJAX for keeping in touch with the server.
You can use document.getElementByTagName().
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
mcowan
Member
8 Points
42 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 19, 2009 10:13 PM|LINK
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
Danny117
Star
11160 Points
1932 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 20, 2009 01:01 AM|LINK
jquery http://docs.jquery.com/Selectors/attributeContains#attributevalue
Me on linked in
mcowan
Member
8 Points
42 Posts
Re: How do you find elements when all you know is a part of its class?
Mar 20, 2009 01:12 AM|LINK
I see the confusion in the responses to my posts. I apologize for my horrible communication skills in this thread. Let me clear things up.
I know HOW to use javascript when I am developing my own ASP.NET web pages. I don't need any help writing javascript code or syntax (but thanks for the jquery link, its cool)
What I am confused on, is that a previous post made it sound like it is possible to use the ASP.NET QA Lightweight Test Automation Framework to test http://google.com/index.html and use custom javascript INSIDE the test method (not on the google index.html page) to parse a classname.
I did not think it was possible to use javascript inside the C# test code to interact with webpages. If it is possible to inject javascript using this framework that would be AWESOME and I would love to know how to do it.
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
farmas
Participant
1164 Points
259 Posts
Microsoft
Re: How do you find elements when all you know is a part of its class?
Mar 28, 2009 07:57 PM|LINK
Michael, your suggestion sounds good and we are including it in our next release. Currently, its looking something like this (names may change):
<div>public enum MatchMethod</div> <div>{</div> <div> Literal,</div> <div> EndsWith,</div> <div> Contains,</div> <div> Regex</div> <div>}</div> <div> </div> <div>public class HtmlAttributeMatch</div> <div>{</div> <div> public string Name {get; set;}</div> <div> public string Value {get;set;}</div> <div> public MatchMethod ValueMatchMethod {get;set;}</div> <div> ...}</div> <div> </div> <div>public class HtmlAttributeMatchCollection: List<HtmlAttributeMatch></div> <div>{</div> <div> public void Add(string name, string value) {...}</div> <div> public void Add(string name, string value, MatchMethod valueMatchMethod) {...}</div> <div>}</div>
One of the tricky things is how to deal with the current TreadIdAs. I am thinking of completely removing it instead of deprecating it, I mean we can fix the tests on our side relatively easily. Would you be ok with this?
- Federico